[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 28
File: prolog.png (18 KB, 512x512) Image search: [Google]
prolog.png
18 KB, 512x512
What are you working on?

Think logically - use Prolog.
>>
How long does it take for me to be able to feel confident about programming?

I think I'm too stupid to make it.
>>
>>51254553
If it ever happens it's a sure sign you're a retard.
>>
>>51254553
>I think I'm too stupid to make it.

You're probably right. You should get out while you can
>>
File: John lennon.jpg (90 KB, 900x900) Image search: [Google]
John lennon.jpg
90 KB, 900x900
>>51254553
Never anon, never..
>>
>>51254553
just do it
make sure you learn the basics. then keep learning, and just do whatever you want to do... or at least try to
>>
File: umaruic.webm (1 MB, 640x360) Image search: [Google]
umaruic.webm
1 MB, 640x360
Ask your beloved programming literate anything.

>>51254500
>Prolog
prolog is a dead end.
>>
>>51254553
What this guy said >>51254583
It's fine thinking you know nothing (assuming you actually do know some stuff) since you know how much you don't know, it's when you think you know everything that you should be worried.
>>
>>51254500
What does this write?

for (i = 0; i < 5; i++)
for (j = 0; j < 5; j++) {
if ((i + j) % 3 == 0) break;
printf("%d %d\n", i, j);
}

>>
Rewriting the linux kernel in haskell.
>>
>>51254603
How do you know you're going to like programming, what if all i really like to do is break computers and play games.
>>
in case the one guy from the old thread who was messing around with amazon/flask is here:
this works for me
from flask import Flask
import requests
from bs4 import BeautifulSoup
app = Flask(__name__)
app.debug = True
@app.route('/books')
def books():
url = requests.get("http://www.amazon.com/gp/search/ref=sr_pg_1?fst=as%3Aoff&rh=n%3A283155%2Cn%3A5%2Cn%3A3839%2Cn%3A3944%2Ck%3Aprogramming&keywords=programming&ie=$
soup = BeautifulSoup(url.text, 'html.parser')
links = soup.findAll('img', src=True)
images = ['<img src="%s"></img>' % link.get('src') for link in links]
return str(images).strip('[').strip(']')

if __name__ == '__main__':
app.run()
>>
File: Capture.png (11 KB, 370x343) Image search: [Google]
Capture.png
11 KB, 370x343
>>51254631
for you
>>
>>51254664
>&ie=$
shit, didn't copy all of it correctly, my bad
from flask import Flask
import requests
from bs4 import BeautifulSoup
app = Flask(__name__)
app.debug = True
@app.route('/books')
def books():
url = requests.get("http://www.amazon.com/gp/search/ref=sr_pg_1?fst=as%3Aoff&rh=n%3A283155%2Cn%3A5%2Cn%3A3839%2Cn%3A3944%2Ck%3Aprogramming&keywords=programming&ie=UTF8&qid=1447025233", headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0'})
soup = BeautifulSoup(url.text, 'html.parser')
links = soup.findAll('img', src=True)
images = ['<img src="%s"></img>' % link.get('src') for link in links]
return str(images).strip('[').strip(']')

if __name__ == '__main__':
app.run()
>>
>>51254676
>it compiled
>therefore it is defined

Kill yourself
>>
>>51254633

It would be funny if someone actually tried to do this.
>>
>>51254676
learn c or stay with js
>>
want more input on
>>51253912
ples
>>
>>51254731
just write an OS in TAL
>>
>>51254731
Well, someone took the "write a web server in assembly" meme and made that real. Maybe one day.
>>
File: Determinants.png (6 KB, 981x87) Image search: [Google]
Determinants.png
6 KB, 981x87
Is there a better way to skip a single item at a nth position in a list in F#? Using mapi to mark the index and choose to skip that position seems overkill.
>>
>>51254676
based java
>>
>>51254625
>> 0 0
>> 1 1
>> 2 2
>> 3 3

Yes?
>>
>>51254827
>>
>>51254865
there may not be but there are certainly better ways to calculate a determinant
>>
>>51254553
Don't worry anon, I've been doing it for over a decade and I still don't feel confident, even though I often dabble with production code.
>>
>>51254625
>0 0
>0 1
>0 2
>1 0
>1 1
>2 0
>4 0
>4 1
>4 2
>4 3
>4 4

Is it correct?
>>
File: wew.webm (554 KB, 1618x716) Image search: [Google]
wew.webm
554 KB, 1618x716
>>51254755
I'm confused on what you are trying to do
like build a set of tools and put them in one program to manipulate a set of objects?

Or build a library to make tools from to do this?

it sounds like you want to make a level designer, which is one component
but there is far more to it than that. like handling positional audio inputs/outputs, for example
>>
File: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.jpg (2 MB, 2736x3648) Image search: [Google]
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.jpg
2 MB, 2736x3648
Taking a distributed systems class next quarter. I think the language they use is Go. Any advice? I've never used Go before.
>>
>>51254625
1 0
1 1
2 0
4 0
4 1
>>
>>51254951
you could try learning go
>>
>>51254500
int a = 3, b;

b = ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a;


Someone said it was 114 but when I compile and run it's 115.
>>
>>51254936
Just have a big set of functions I can call to create lines and other miscellaneous shapes, and then more functions to manipulate them
this would have no graphics, just arrays with coordinates in them, I could use something else to change those coordinates into pixels

I don't know how this kind of thing is really supposed to be done
>>
>>51254958
Yeah.
>>
>>51254970
That someone doesn't know C, just like you.
>>
>>51254968
Have any recommendations on good resources for that?
>>
>>51252303
Stole that python code, it's so much more elegant in Haskell.

π α ω   | ω == 1 = "e"
| ω == 2 = "0"
| otherwise = show ((ω - 2) `mod` α) ++ π α (1 + α - 2)
>>
>>51255000
The official resources are good enough.
>>
>>51254970
>gcc
that's why
>>
>>51254500
just finished an AI assignment with Prolog was pretty fun
>>
>>51254970
is multiple increments on the same line a form of undefined behaviour?
>>
>>51254986
if I just spoonfed you everything you'd never learn, this is a journey you need to go on yourself, young one
good luck

if you have the pasión you'll get it eventually
>>
>>51255043
>dumb as fuck
>>
File: why.jpg (63 KB, 385x329) Image search: [Google]
why.jpg
63 KB, 385x329
Why isnt this working?

I just want to sum the contents of the array but for some reason I am getting the result of 20.

 #include<stdio.h>

int main(void)
{
int numbers_array[4] = {1, 2, 3, 4, 5};
int i, sum = 0;

for( i = 0; i <= 4; ++i ){
sum += numbers_array[i];
}

printf("%d", sum);

}
>>
>>51254676
>2015
>side effects
top lmao
>>
>>51255075
no
>>
>>51255138
Look at the array and tell me what's wrong with it
>>
>>51255138
You define numbers_array as 4 elements but the array literal you initialize it with has 5 elements.
Surely the compiler gives a warning for that
>>
Someone have that image that has 100 or so programming projects to learn programming with, starts off with simple things and gets progressively more difficult?
>>
File: oop_mistake.jpg (179 KB, 500x666) Image search: [Google]
oop_mistake.jpg
179 KB, 500x666
I seriously hope /g/ didn't fall for the OOP trap.
>>
>>51254951
It's a bad language.
>>
>>51255135
why ?

clang: 114
java: 114
dmd: 114
c#: 114
mathematics: 114
>>
>>51255223
>clang: 114
undefined
>mathematics: 114
mathematics doesn't have ++
>>
>>51254951
tour.golang.org
>>
>>51255223
tcc thinks it is 114 as well
>>
Any tips before i chop off my leg and sacrifice it to satan to hopefully learn c?
>>
>>51255299
learn scheme or racket first instead, then learn forth, then if you really think something didn't meet your needs you have my permission to learn C
>>
>>51255299
Yeah, close that tab and order C Programming: A Modern Approach
>>
>>51254500
How much is x?

int x = 0;
if (x > 3);
x++;
>>
>>51255331
This is your C level?
>>
>>51255329
>``modern''
meme detected
>>
>>51255261
>mathematics doesn't have ++
mathematics has anything you want to. over time, mathematicians continuously defined their own syntax. you should know that.
>>
>>51255341
>botnet
>>
>>51255331
uhm compile error is how much x is
>>
>>51255331
1.

>>51254915
Made a function to remove the line and the column. It's so ugly...

let remove x y l = 
l
|> List.mapi (fun n l -> n, l)
|> List.choose (fun (n, l) ->
if n = y then None
else
Some(l
|> List.mapi (fun n l -> n, l)
|> List.choose (fun (n, l) ->
if n = x then None
else Some l)))
>>
>>51255329
Wow it's only $100
>>
File: 3mLydMU.png (70 KB, 243x200) Image search: [Google]
3mLydMU.png
70 KB, 243x200
>>51255043
>>51255223
it's undefined in C/C++ baka desu senpai
>>
>>51255356
you should know they didn't define ++
>>
>>51255299
I didn't think C was a particularly difficult language to learn. The best advice I can give before learning C is to learn about memory addresses, the heap, the stack, how values are stored by programs. C makes explicit use of memory allocation and addressing. I wish I had learned about the aforementioned before learning C. It would have made pointers so much more understandable.
>>
>>51255395
>before learning C is to learn about memory addresses, the heap, the stack
they have nothing to do with c
>>
why do comp science majors need to learn calculus anymore?

ive been making a game and have wrote solutions using algebra, trig, discrete math, and thinking geometrically at times.

not once have i caught myself thinking in terms of derivatives or integrals.

the only time ive even seen calc with programming stuff was a thick dated book defining 3d with various iterated mutliple integrals.
>>
>>51255380
Get it used
>>
File: WTF Freddy.jpg (71 KB, 800x550) Image search: [Google]
WTF Freddy.jpg
71 KB, 800x550
What languages that would let me do website log-ins don't require that I set up a "working server" just to learn them?

I only have one computer and really don't want to dual-boot for this nor do I want to actually stick stuff online as I'm just starting. My goal is a basic log in and log out plus a welcome page all of which should be accessable via a web browser.

For the love of god don't say Javascript or Java. I want to see what other languages are out there.
>>
>>51255429
Would it be worth it to use the site then get the book after, or should i just get it now?
>>
>>51255380
http://g.sicp.me/books/
>>
>>51255426
never, since so-called ``real'' numbers don't exist
>>
>>51255299
Abort now or be doomed to hell forevermore.
>>
>>51255381
still that gcc defined it wrong.
>>
>>51255465
>being this retarded
>>
>>51255465

That's because GCC is deprecated.
>>
>>51255465
>full retard
>>
>>51255465
no, the compiler is allowed to do whatever the fuck it wants to if you have undefined behavior in your program http://www.catb.org/jargon/html/N/nasal-demons.html
>>
cloning tetris brb
>>
File: 1359236051-gcc-llvm.jpg (106 KB, 1070x400) Image search: [Google]
1359236051-gcc-llvm.jpg
106 KB, 1070x400
>>51255476
>>51255483
>being this upset for such a thing
lel.
>>
>>51255465
>undefined
>gcc defined it wrong
anon...
>>
There are two buttons in front of you, /dpt/. Once you press one and activate it, neither ever work again.

The button on the left will eliminate your most hated programming language from existence. The button on the right will turn you into a beautiful 14 year-old girl, complete with all your current knowledge and memories, but if you ever program in anything but your most hated language you die a slow, painful death.

Which do you press?
>>
File: mBN4gzG.png (40 KB, 755x620) Image search: [Google]
mBN4gzG.png
40 KB, 755x620
>>51255506
>>
>>51255517
Button on the right, obviously. That's not even a choice.
>>
>>51255482
your face is deprecated lmao
>>
Writing up a web scraper for a friend. She has this online course with a bunch of chapters/modules and wanted to store them locally for future reference. I'm doing it in C# since its the language I know best. Started it last night and realized I couldn't pass in the login info via post to get into the site so I have a temporary workaround of having it open a web browser window, me login using the info, then clicking a scraper button to do the work once in.
>>
>>51255495
sure but what gcc does here is wrong.
>>
>>51255517
left

eliminate python
>>
>>51255517
Neither
Left if I have no choice
>>
>>51255517
>wait until I'm in my deathbed
>hit button on the right
>become young again with insane knowledge
>use the knowledge to show grade-school friends how to catch mew in pokemon blue

feels good
>>
>>51255540
says you
>>
>>51255540
>being this butthurt
>>
>>51255538
>and realized I couldn't pass in the login info via post to get into the site
why not?
>>
>>51255538
>doing homework for a girl

She isn't going to sleep with you, beta. She'll just use you to do her homework
>>
>>51255563
i am not butthurt at all, just saying the truth. gcc is the only one returning 115 which is mathematically wrong. see
>>51255223
>>51255297
>>
>>51255568
because i'm insecure
>>
>>51255581
[butthurt intensifies]
>>
>>51255581
hurp a durp
>>
>>51255582
....?
C# should definitely be able to emulate most browser requests, including logging in.
>>
>>51255602
i already told you i'm insecure (.__.)
>>
>>51255616
what the fuck does that have to do with solving the problem
>>
>>51255540
what you do here is wrong
>>
>>51255625
(.___.)"
>>
>>51255616
Insecure meaning shy, scared and with low confidence and self-esteem.
>>
>>51255581
there's no ++ in math, so it can't be mathematically right or wrong; you're imagining things
>>
>>51255001
I have ghci but I never learned haskell, how do I use this
>>
>>51254500
int a = 3, b;

b = ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a + ++a;


So, was it 114 or 115? Or 36? And why would anyone write code like this?
>>
>>51255172
>>51255170

Yes, but dont Arrays start at 0?

So that means 0, 1, 2, 3, 4. So 5 elements?
>>
>>51255670
>why would anyone write code like this
retarded
>>
>>51255670
it's undefined
>>
>>51255670
it can be 2
>>
>>51255688
well then gcc defined it wrong.
>>
>>51255687
posting on 4chan is a violation of the rust CoC please stop using rust

thank you
>>
>>51255696
you don't seem to understand the concept of undefined; undefined can't be "defined right"
>>
>>51255696
Ever epic. Epin even. In my opinion, it reaches at least the rank of equine.
>>
>>51255637
so I'm guessing you don't want help, then
>>
>>51255681
no
you said you have an array with 4 numbers
4 as in 0,1,2,3. you can only put 4 numbers in there
and a note on good practice

do this
for (int i = 0; i < 5; i++) {
rather than <= 4. It's the same thing but it is clearly 5 numbers that fit there, since a 6th is equal to i=5
>>
>>51255670
I could write a compiler that emits code that will delete your home directory when it encounters that and it will still be a conforming C compiler.
>>
>>51255670
The correct answer is 3.
>>
>>51255752
this is how all compilers should treat undefined behavior desu
>>
>>51255752
>I could write a compiler
>posting on /g/
Somehow I doubt you have the skills to do that.
>>
>>51255696
undefined means the compiler can do whatever it wants with that code

if gcc thinks that means execute "rm -rf /" then it can do that and still be ANSI C compliant
>>
>>51255670
The correct answer is -1.
>>
>>51255775
no, they should just produce efficient code
>>
>>51255778
There are 3 people who post on /dpt/ and are currently making compilers.
>>
>>51255796
you can delete files efficiently
>>
>>51255799
is this YLYL, /dpt/ edition?
>>
>>51255778
Writing compilers isn't even that hard. Writing an optimising compiler is hard.
>>
>>51255681
The elements in the array are numbered in that fashion, but the number used to initialize an array of a certain size must be equal to the total amount of elements in the array.

tl;dr you created an array of size 4 and then tried to add 5 elements to it
>>
>>51255807
not as efficiently as doing nothing
>>
>>51255815
>being this jealous
>>
>>51255819
Please, we're talking about monkeys that can't even average two numbers.
>>
>>51255799
>currently dream about making compilers
ftfy
>>
>>51255830
Are you suggesting that you rely on undefined behavior in your code and wish it to be "optimized"?

lel
>>
>>51255862
no
>>
>>51255861
>looked up the word "compiler" on wikipedia
ftfy
>>
>>51255845
>>51255861
Not everybody is as stupid as you.
Stop projecting.
>>
>>51255861
One has a working complete compiler. One has a working lexer, parser and type inference. The other has a working parser and lexer.
>>
>>51255878
Yeah, they're worse.
>>
>>51255654
++a is same as a += 1 which is same as a = a + 1.
>>
>>51255881
>working
Sure thing.
>>
>>51255873
Then it is no problem whether the code which deletes your home directory is efficient or not.
>>
>>51255781
>the compiler can do whatever it wants with that code
and gcc decided to do it wrong.
>>
>>51255908
[citation needed]
>>
>>51255913
You're spilling your jelly everywhere, dude! Careful!
>>
File: 07.jpg (795 KB, 936x1404) Image search: [Google]
07.jpg
795 KB, 936x1404
>>51255908
>0=1
nice math

>>51255926
it's getting pretty EPIC MEME in here
>>
>>51255919
other than not being efficient? nope
>>
>>51255928
http://port70.net/~nsz/c/c11/n1570.html#6.5.3.1p2
shut up now
>>
>>51255908
a = a + 1
in C means
a ← a + 1

The same guys who think addition should be written
(+ 1 2)
get confused by this use of = because it doesn't work like math.
>>
>>51255517

I have no desire to lose my penis, so I guess PHP gets to die. Everyone is now forced to use something else and half the Internet stops working. This, I consider to be an acceptable tradeoff for a world without PHP. While 4chan would not work for a while, there are other experimental imageboards using Node.js, which might be used in the mean time until something better comes along.
>>
>>51255957
that defines it in c; we were talking about math; pay attention, monkeyboy
>>
>>51255967

Can you really not think of a worse language than PHP?
>>
>>51255938
>out of arguments
>>
I hate you all
>>
>>51255957
That's about C, not mathematics.
>>
I was working on a web app where users could vote if current trending twitter topics is "fucking ridiculous" a la Kanye West's "So Appalled"

unfortunately, twitters API is sort of a bitch, and doesn't really seem to allow me to easily fetch trending topic data. Does anyone know about this?

what they do allow me to do, however, is create a livestream of someones twitter profile. by doing this, this allows me to create a bullying platform where users can vote if someone's tweet is fucking ridiculous. I could then put these votes into a database and display the worst tweets of all time. which I guess is pretty sweet, but not exactly what I was trying to do
>>
>>51256010
and everyone hates you
>>
>>51254754
I see no reason why this shouldn't work as (++a) + (++a). Am I missing something here?
>>
>>51256040
The order of evaluation in C is unspecified. It allows for much better compiler optimisations with instruction reordering.
>>
>>51255919
Why would it go to the trouble of generating code to delete a directory when it could simply not generate anything at all?
>>
>>51255538
or you can just use beautifulsoup
here, modify this
from bs4 import BeautifulSoup
from datetime import datetime
from requests import get
from sys import argv
import os


def rn():
return str(datetime.now()).replace(' ', '_')

url = argv[1]
thread_request = get(url)
if thread_request.status_code != 200:
raise Exception('Thread URL not found')

thread_soup = BeautifulSoup(thread_request.text)

image_links = thread_soup.select('.fileText a')

folder_name = rn()
if not os.path.exists(folder_name):
os.makedirs(folder_name)

for index, image_link in enumerate(image_links):

print 'Scraping ' + str(index + 1) + '/' + str(len(image_links))

image_url = image_link.get('href')
if image_url[:5] != 'http:':
image_url = 'http:' + image_url
image_request = get(image_url)

if image_request.status_code in (200, 304):

content_type = image_request.headers['content-type']
extension = ''
if 'png' in content_type:
extension = 'png'
elif ('jpg' in content_type) or ('jpeg' in content_type):
extension = 'jpg'
elif 'gif' in content_type:
extension = 'gif'

filename = rn() + '.' + extension
file_path = os.path.abspath(os.path.join(folder_name, filename))

with open(file_path, 'wb') as output:
output.write(image_request.content)

alternatively you could use wget or curl, which would be way easier. just tell the user to paste this command into their command prompt

wget -r -np -k http://www.ime.usp.br/~coelho/mac0122-2013/ep2/esqueleto/
[/code
https://superuser.com/questions/200426/curl-to-download-a-directory
>>
>>51256049
You missed the entire point of the statement.
>>
>>51256040
you are missing a sequence point
>>
>>51256049
Because modern compilers are so intelligent, they can optimise away all the unnecessary features in your life
>>
>>51255989

It's hard to hate what you've never used. I am fairly sure COBOL probably is the worst language in use today that isn't a turing tarpit. That said, since I haven't used it, I discount it from the list of languages I hate. I have used PHP before, and it was not a pleasant experience. Besides, making 4chan and Facebook stop working is a lot worse than making all of the world's banks stop working. My credit union will still have my account balance, even if nobody can do online banking. The same cannot necessarily be said if COBOL stopped existing.
>>
>>51255989
Pair program in D with me :3
>>
File: fuckyourmemebooksBjarne.png (298 KB, 1920x1080) Image search: [Google]
fuckyourmemebooksBjarne.png
298 KB, 1920x1080
Halp pls , don't tell me this meme book wasn't even "tested" with VC++.
>>
>>51256048
but, in
int a = 3, b;
b = ++a + ++a;


the expressions of
b = ++a + a++;
are
//those threes can be evaluated in any order.
subexp1 = (a = a + 1)
subexp2 = (a = a + 1)
subexp3 = b

//last expression
subexp4 = (subexp3 = subexp1 + subexp2)


so it's either
b = 4 + 5
or
b = 5 + 4
which is the same.
>>
>>51256060
no, you missed it
>>51255752
>>51255775
>>51255796
compilers shouldn't emit code to delete your home directory on undefined behavior, they should just do their job which in that case is nothing. they CAN delete and be conformant but why bother. one that just does its job as swiftly as possible with no cutsey bullshit is better than the "fun" one.
>>
>>51256063
>braindamage
>>
>>51255426
>why do comp science majors need to learn calculus anymore?

It's probably because of tradition and university organization.

1 - Computer Science are generally taught in universities under either the engineering and science faculties and their general degree structure. Even if comp sci student don't need much, physicists and civil engineers use much more. So everybody will take the same basic math courses: Cal I, Cal II and Linear Algebra (maybe stats?).

2 - Cal courses probably also serve as an extra weed-out courses. Why do you think they require business majors to also take course?

3 - Okay, it also keeps the math department healthy and hale.
>>
>>51256141
>so it's either b = 4 + 5 or b = 5 + 4 which is the same
There are lots of situations where that is not true. Having silly special cases where it would be allowed is stupid.
>>
>>51256137
sort() takes 2 arguments
>>
>>51256184
And what are those?
I only see 1 vector ( temps)
>>
>>51256137
sort (temps.begin(), temps.end())
>>
>>51256200
thanks
>>
having some trouble with this
ok let's say we have an array of a bunch of shapes
I want to check if any shape is intersecting another shape in that array
I can do this just fine but the problem is doing this intersection test includes itself!
like in this example:

for(Rectangle c : tiles) {
if (c.getCenterY() < 500)
c.setCenterY(c.getCenterY()+(delta/5f));
}


if I made a test for:

if (c.intersects(c))


this includes itself in the search
any way around this?
>>
>>51256141
no, the expressions are
// evaluated first
t1 = a + 1

// these can be evaluated in any order
a = a + 1
t2 = a + 1
a = a + 1

// evaluated last
b = t1 + t2
>>
>>51256080

Fair enough

>>51256109

Maybe one day.
>>
>>51256216
note the problem isn't in vc++
your book is simply outdated
google std::sort and you'll find documentation
>>
>>51256217
ok one possible solution was to create an array and say these values are off-limits, every time a peice stops moving store its coords in an array, then check constantly if a peice is intersecting the illegal value
there must be a better way than that though
>>
>>51254500
How to calculate a square root of some number using only addition, subtraction, multiplication and division?
>>
>>51256241
seriously...

I really took my time to find the latest "non-meme" book who not only has good references but good practices...

this book is like from q2 2014..
>>
>>51255223
>>51255297
Also 114 with intel c++
>>
>>51256287
then maybe I'm wrong, I'm not a C++ guy.
still, googling for std::sort gives you a few results that all seem to need two arguments, a start and end.
>>
>>51255075
>>51255155
Yes it is. The compiler is free to do whatever it wants. You can't trust the result.
>>
What's the latest non-meme C# book?
>>
>>51256334
>well, you have to trust the result, unless you want to translate it into assembly, then binary on your own
>>
gcc 5.2
  int a = 3;
int b;
b = ++a + ++a;

compile to
    mov    DWORD PTR [rbp-4], 3
add DWORD PTR [rbp-4], 1
add DWORD PTR [rbp-4], 1
mov eax, DWORD PTR [rbp-4]
add eax, eax


what gcc actually does

int a = 3;
++a
++a
b = a + a


wtf ?
>>
>>51256334
read the question again
>multiple increments on the same line
you are free to have multiple increments on the same line, like
a = b++ + c++ + d++;

or with the same variable
a = b++; a += b++; a += b++;

you only need some sequence points along the way.
>>
>>51256340
>latest
well, this isn't the latest, but I learnt C# from
http://www.amazon.com/Programming-Language-Covering-Microsoft-Development/dp/0321741765
I find it was good as it was annotated by a few C# VIPs
>>
>>51256324
Yea, i thought so because when i used the function i saw the 2 parameters needed.

Still, maybe i'm too retarded and jumped too early into conclusions since i didn't read the rest of the chapter.

Thanks anyways, i guess i'll have to google the documentation pretty often now.
>>
how would you make this implementation of RSA secure

fn mod_pow(b: u64, e: u64, m: u64) -> u64 {
let mut c = 1;
let mut e_prime = 0;

loop {
e_prime += 1;
c = (b * c) % m;

if e_prime >= e {
break;
}
}

c
}

fn encrypt(msg: u64, key: (u64, u64)) -> u64 {
mod_pow(msg, key.1, key.0)
}
fn decrypt(enc_msg: u64, key: (u64, u64)) -> u64 {
mod_pow(enc_msg, key.1, key.0)
}
>>
>>51256340
>>51256389
and it's only 850 pages, a pretty quick read
>>
>>51256362
correct, that's what you wrote.
>>
>>51256217
That will only ever test with itself
If Rectangle has an != operator

for (Rectangle c : tiles)
{
//some stuff
for (Rectangle d : tiles)
if (c != d && c.intersects(d)
{
//collision
}
}
>>
>>51256386
Well sure, fair enough. I was mainly alluding to the original case of incrementing the same variable multiple times within one sequence point. Then again looking a bit further it seems that already got established along the way (thankfully).
>>
Is Node.js the future?
>>
>>51256404
so gcc is really this retarded ?
>>
>>51256403
>>51256389

Checking it out, thanks, mang.
>>
>>51256422
I know what you were referring to, I was just messing around with useless pedantry (of addressing the question as written). Sorry about that.
>>
>>51256449
how is it retarded if it generates correct code? it generates correct assembly for the c code you wrote.
>>
>>51256452
according to the back of my book, you can read an online version free for 30 days at safaribooksonline.com
>>
Alright /g/ I want to learn a new language that I can do something with.

Know:
Java
Objective C
Python

What should I learn? The only thing I do not want to attempt is scripting languages or assembler.
>>
>>51256394
using keys larger than 64 bits would be a good start.
>>
>>51256362
>>51256449
You wrote code that is defined as undefined behavior. Don't blame the compiler for your own idiocy.
>>
>>51256494
Go.
>>
>>51256494
>Java
Have you delved into the world of enterprise java?
>>
File: epwor.png (65 KB, 902x839) Image search: [Google]
epwor.png
65 KB, 902x839
>>51256477
>>51256452
one of the most interesting thing I find is that in defining things, it uses the actual syntax that the parser/compiler would use. When I was learning C#, it gave me a real insight into how everything worked. Much better than other material.
>>
>>51256476
mov [a], 3
add [a], 1
mov eax, [a]
add [a], 1
add eax, [a]
>>
>>51256500
well, let's be realistic, key size is the low-hanging fruit.
>>
File: p1.png (9 KB, 399x172) Image search: [Google]
p1.png
9 KB, 399x172
>muh FP languages
>lol imperative plebs
>lol C++ meme

fuck you this is valid C++
>>
>>51256394
This is Swift, right? How are you defining a constant with 'let' but modifying it later? I'm not an expert, just looked into the language a bit some time ago.
>>
>>51256476
what gcc does is (++a, ++a, a + a), that's fucking retarded and has nothing to do with evaluation order.
>>
>>51256547
it's Rust
>>
>>51256545
(3_mi, 4_mi)?

>>51256565
And it can do that because the standard says the compiler can do whatever. Stop writing retarded code for one thing.
>>
>>51256547
and it's done by "borrowing" it. the mut turns it into a mutable type
>>
>>51256606
Ah ok, the syntax apparently just is very close to Swift's, as far as I remember it.
>>
>>51256610
user defined literals
>>
>>51256631
that's good because i planned on rewriting some old apps in swift to get a jump start on the language
>>
>>51256632
Guess I need to familiarize myself further with 11/14.
>>
>>51256644
btw, is it good for learning the osx api's too? cocoa and all that jazz?
>>
>>51256649

Meta<int> operator "" _mi (unsigned long long int x) { return store(int(x)); }

there are a specific set of parameters you're allowed to use, but the general form is
<some_type> operator "" literal_postfix (one specific param)
>>
>>51256545
I'm not sure if showing that C++ can do something functional in a weird syntax and probably without support to partial application is a good way to show your point. Try showing some algorithm that is easy to do in C++ but hard in functional languages.
>>
I have a Go question about interfaces. So I have this code
type Abser interface {
Abs() float64
}

type Vertex struct {
X, Y float64
}

func (v *Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}

So when I try to do this
var a Abser
v := Vertex{3, 4}
a = &v
a = v

I get an error on the line "a = v" because Abs() was only defined for the *Vertex type and not the Vertex type. However if I change the Abs function to this
func (v Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}

And run the above code it works now. Both "a = &v" works and so does "a = v". Why does "a = &v" work if I have only defined Abs for Vertex and not *Vertex though?
>>
>>51256716

There are things it can't do, for instance in this example 3 and 4 have to be the same type (meaning the calculation is done lazily at runtime) because it can't specialise squared by itself yet

It's like this:
(3), (4) -> (3, 4)
(3, 4) | x -> (x(3), x(4))
(3, 4) >> y -> y(3, 4)

Anyway, I'm inept at programming useful things
>>
>>51256764
I might add in something so you can do
(3, 4) | (x, y) -> (x(3), y(4))
that'd be a (possibly simpler) way to get purely static evaluation
>>
>>51256764
Language acrobatics.
>>
>>51256673
This is designed to be used specifically for unit conversion? Like the chrono literals?
>>
>>51256362
Don't increments/decrements before the variable happen before any calculation?
So wouldn't
b = ++a + ++a;
be the same as
b = (a+1) + (a+1);
?
>>
>>51256822
yes

I'm using msvc++ 2015 btw
>>
>>51256545
>>51256716
A function is just a set of ordered pairs to be honest family.
>>
btw the previous version also let you take items, with a start/count/step. could've added a conditional one too
>>
>>51256407
oh that's clever, thanks
>>
>>51256832
but ++a modifies a, it's

b = (a+=1) + (a+=1);
>>
>>51256878
http://en.cppreference.com/w/cpp/language/user_literal
>>
>>51256893
Ah, right, that's what I meant.
>>
>>51256919
sure it is, retard
>>
>>51256931
Bitch if I know they have a higher precedence I obviously know they add to the original as well.
>>
>>51256960
i don't think you know anything.
>>
>>51256893
>>51256919
>>51256931
>>51256960
>still arguing about undefined behavior
>>
>>51256972
k
>>
Just learning C#. What exactly is happening in the above posts with regards to this code:


int a = 3, b;



What the hell is b? When/how is it initialized and what is it assigned?
>>
>>51257067
int a, b = 3
>>
>>51257081

That's all? It's just a bizarre way of initializing both to 3? Is there a word for this behavior that I can read about?
>>
>>51257067
Assuming what the other guy said is correct, the guy who wrote that needs to be shot.
>>
>>51257067
There's only one way to find out.

Compile and test it
>>
>>51257067
b is undefined, it hasn't been initialized yet
basically it's shorthand for
int a = 0;
int b;

so later if I said b = 3
it would be initialized on that line
>>
File: Unitialized.png (3 KB, 267x74) Image search: [Google]
Unitialized.png
3 KB, 267x74
>>51257067
Download LINQPad.
>>
>>51257067
>>51257108

As you guys pointed out I should try and figure it out myself. So I put it all in and it looks like it creates but does not assign a value to an int named 'b'. That's interesting behavior, I wouldn't have expected it to do that, and I'm not really sure why it's an option.
>>
File: unassigned_int.png (126 KB, 2560x1600) Image search: [Google]
unassigned_int.png
126 KB, 2560x1600
>>51257202

Thinking about it more I guess it could be useful for creating multiple variables in one line when you only have a value for one. But still, it seems unnecessarily complex.
Thread replies: 255
Thread images: 28

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.