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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 321
Thread images: 31

File: logocaml-oreilly.gif (5KB, 375x352px) Image search: [Google]
logocaml-oreilly.gif
5KB, 375x352px
old thread >>52538609

What are you working on, /g/?
>>
STATIC TYPING

NO TYPE INFERENCE

NO OPERATOR OVERLOADING

JAVA ÜBER ALLES

SIEG HEIL
>>
>>52543079
>not using an anime trap image

Fuck you. go back to reddit. This is an anime thread. fuck programming
>>
>>52543079
Official OCaml thread! My dream is finally realized! My God has answered my prayers! Praised be to him! Another 1000 lines of code shall be sacrificed to His Glory!
>>
>>52543116
>NO OPERATOR OVERLOADING
While it gets messy, I'd like something like "scoped operator overloading".
You'd explicitly state what operators get overloaded with what and its only in that file/block
>>
File: 1453201739293.png (2MB, 514x989px) Image search: [Google]
1453201739293.png
2MB, 514x989px
>>52543163
>>
>>52543212
So, like in ocaml then.
>>
>>52543211
307 posts, no new thread. I had to do it. So I did it.

OCAML MASTER RACE

let not_yet s _ = failwith (Printf.sprintf "not yet: %s" s);;

let fdebug f =
if Config.get_debug () then
Format.eprintf "@[<2>#%f %t@]@." (Sys.time ()) f
;;

let mmod a b =
let c = a mod b in
if c < 0 then c + b else c
;;

let map f l = List.rev (List.rev_map f l);;

let append l1 l2 = List.rev_append (List.rev l1) l2;;

let with_open_in file f =
let ic = open_in file in
try
let r = f ic in
close_in ic;
r
with
| x ->
close_in ic;
raise x
;;
>>
>>52543233
>writing in topscript
>2016
>>
>>52543279
topscript?
>>
>>52543227
ocaml doesn't even have function overloading
>>
>>52543116
>NO OPERATOR OVERLOADING
I never got why people wanted to avoid this. In my mind this is just equivalent to allowing people to come up with their own function names. Nothing is preventing anybody from writing a function plus : R -> R -> R which actually multiplies the arguments instead of adding them.
>>
>>52543289
>function overloading
Totally useless.
>>
>>52543289
MyModule.(overloaded 3 4)
Dicks.(overloaded 8 9)
MyModule.overloaded 3 (Dicks.overloaded 18 29)
???????????????
?????
>>
>>52543293
you don't need both. functions/methods are sufficient. without operator loading you ALWAYS know what an operation does regardless of the context of the code. also a function/method name can be much more expressive and descriptive than just a symbol.
>>
>>52542929
>maximum damage control
>>
What's the best/fastest algorithm for comparing elements in an array, generating a new array of links between them in which link[i,j] == link[j,i]? I mean don't compute a link if the reverse link exists.
>>
>>52543327
It really makes things a lot less clear when you have to do a lot of calculations with non-primitive types like matrices or polynoms.
>>
>>52543293
because most of the programmers are mediocre.
>>
>>52543354
That's what delimited overloading is for. Be it with
open Module

or
Module.(everything in here uses the overloaded methods until the last paren)
>>
>>52543321
I don't know what that's supposed to be but it ain't overloading.
>>
>>52543293
if you write a function called plus then it's clear as day that a * b is a mistake. if you overload + to be * then you'll be like "what the fuck?" and not be sure what the author really meant, like maybe they did it as a lazy hack to intentionally change from addition to multiplication?
>>
>>52543401
Could be a typo. For example you're binding cublas for your language and the signature for * and + is the same, so you copy-paste and forget to change the name of the function being called. Point is, operator or function overloading should be treated the same since it has the exact same properties.
>>
>>52543460
except operator overloading fucks with basic language features
>>
>>52543460
if they have the exact same properties, why do you need both? why give up the benefit of always knowing what an operator does, never having to even consider that it might be doing something non-standard?
>>
>>52543481
Such as?
>>
>>52543502
Operators?
>>
>>52543481
Then you should not create a function called log that logs messages. You also shouldn't define a function add that adds matrices together. You shouldn't have a method called next. Inheritance should never be used. Multiple dispatch? Pah! Even single-dispatch should not be allowed!
>>
>>52543460
>since it has the exact same properties.
not necessary, operators can be infix or postfix and have an order of evaluation
>>
O b j e c t i v e s h i t
>>
>>52543500
The exact same statement is true with regard to any function name whatsoever. That's the whole point.
>>
>>52543516
That's standard library stuff that doesn't happen without an include.
>>
I'm making a web crawler and I want to use TOR to not get shitlisted.

System.setProperty("socksProxyHost", "127.0.0.1");
System.setProperty("socksProxyPort", "9050");


Is this enough for IP rotation? How can I further beef up the anonymity aside from random request delays and random link clicking order?
>>
>>52543528
B u t t h u r t
You couldn't name a single flaw in the language that isn't you being struck with a deeply ingrained case of the baby duck.
>>
>>52543536
>core language features and automatically included basic symbols are library stuff that doesn't happen without an include
>>
>>52543513
Doesn't fuck with them if we do not give any type operators by default.
>>
File: giphy.gif (969KB, 500x281px) Image search: [Google]
giphy.gif
969KB, 500x281px
Ask yo beloved programming literate anything.

>tfw there no operators in lisp, only procedures.
>>
>>52543530
fucking idiot
>>
File: 1452450461467.png (17KB, 418x359px) Image search: [Google]
1452450461467.png
17KB, 418x359px
>>52543528
>I don't understand this
>It must be shit
>>
>>52543550
I was talking about functions like log, retard.
I don't care about your babbling about OOP stuff.
>>
>>52543566
fucking inbred
>>
>>52543569
>C is OOP
you heard it here first, folks!
>>
>>52543543
ocaml's oo is shit, even ocaml shills admit that.
>>
>>52543572
you need at least one or the other, and having both is redundant. functions with definable names is the obvious choice. with just operator overloading you'd run out of symbols really quickly.
>>
>>52543579
C has inheritance and methods now?
And they're not OOP?
How fucking dumb are you?
>>
>>52543584
It's the best OOP, it's just that OCaml shills hate OOP. Bust OOP in OCaml is goat.
>>
>>52543116
>no type inference
why.jpg
>>
>>52543616
inb4 12+ hours of spergrage
>>
>>52543616
at least OCaml's kind of type inference is completely retarded
>>
>>52543584
Actually it's the best implementation by far.
>row AND column polymorphism
>pattern matching and least requirements
>multiple inheritance and packing
Literally GOAT
>>
>>52543592
Both and neither work perfectly. Namespaces (such as modules, and then inclusion for overloading) are used to disambiguate.
>>
>>52543604
>inheritance
Can be implemented

>methods
Assuming you mean "virtual functions", then yes, can also be implemented.

However, inheritance and virtual functions are no requirement to be classified as object-oriented. There are many multi-paradigm languages that support OOP without a native implementation of inheritance, JavaScript or Common Lisp for example.
>>
>>52543633
Found the retard.
>>
>>52543667
>Can be implemented
Then they're not basic language features are they?

Are you a fucking gold fish? It's like you always forget everything before the last post.
>>
>>52543692
it's the way of the sperg
>>
>>52543644
Multiple inheritance is disgusting
>>
>>52543592
>with just operator overloading you'd run out of symbols really quickly
You do realise operators can consist of more than one symbol?
>>
>>52543703
THIS

JAVA ÜBERMENSCH
>>
File: 1436550309041.png (491KB, 724x674px) Image search: [Google]
1436550309041.png
491KB, 724x674px
>>52543667
doing oop with c and c being an oopl are two different things
>>
>>52543703
>delicious
FTFY
Enjoy your 2000-deep class hierarchies or copy-pasta code all over the place.
>>
>>52543712
so you'd have code like a b c;

or

bitch nigger;


great...
>>
>>52543718
Tell that to >>52543569
>>
>>52543692
>Then they're not basic language features are they?
No one said so

>Are you a fucking gold fish?
Ditto. The question was whether or not C can be considered OOP.

Neither inheritance nor virtual functions are necessary to be classified as OOP. I just pointed this out.
>>
>>52543592
But they are _not_ redundant. Operator overloading provides a terse way to call functions with non-terse names. Let M be some arbitrary monoid with an arbitrary binary operator ⋆, and x, y, z ∈ M. Then compare x ⋆ y ⋆ z to x.arbitraryBinaryOperator(y.arbitraryBinaryOperator(z)).
>>
>>52543079
>>52543233
> OCaml
Why if we have Rust now?
>>
>>52543713
But Java has multiple inheritance...
>>
>>52543729
nice meme
>>
File: f3h2eqZr.jpg (79KB, 1080x540px) Image search: [Google]
f3h2eqZr.jpg
79KB, 1080x540px
i stopped reading here. on page 272. did they think they were fucking kawaii or something?
>>
>>52543720
There's that thing called composition you know...

Only good OOP is Go's (if it didn't lack polymorphism)
>>
>>52543731
>rust
Laughing_whores.jpg
>>
>>52543735
you can implement multiple interfaces but you can't subclass more than one class.
>>
>>52543725
What? Most languages I have used had operators with more than one symbol.

>=, <=, !=, ==
>>
>>52543728
>No one said so
It's what started this discussion!

Fuck you, I'm done talking to you.
>>
>>52543741
post pdf
>>
>>52543735
No it does not.
>>
>>52543750
In other words, multiple inheritance.
>>
>>52543756
you would be so fucking disgusted you would vomit out of your eyeballs if i did
>>
>>52543751
you'll run out of them if you use them like functions you idiot

and they're horribly nondescript outside of their standard functionality.
>>
>>52543743
I laughed so much that I couldn't laugh anymore. Well played.
>>
>>52543762
>The Java programming language supports multiple inheritance of type, which is the ability of a class to implement more than one interface. An object can have multiple types: the type of its own class and the types of all the interfaces that the class implements. This means that if a variable is declared to be the type of an interface, then its value can reference any object that is instantiated from any class that implements the interface. This is discussed in the section Using an Interface as a Type.

https://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html
>>
>>52543767
kill yourself idiot
>>
>>52543771
This is why I ask for a pdf, I want to see how shit it is.
>>
>>52543777
You won't run out of them any more than you would run out of function names. I didn't say anything about them being descriptive, just that most languages support operators with multiple symbols, unlike what you claimed.
>>
>>52543789
>I have literally no idea what inheritance is
t. java devs
>>
>>52543793
>wahh someone pointed out my ignorance
Grow up.
>>
>>52543789
the "multiple inheritance" in java is a restrictive form where you can only implement multiple INTERFACES (which are not classes by themselves) and you can NOT derive from more than one base class. it's not what you typically mean when you say multiple inheritance.
>>
>>52543805
I can't find a pdf of the whole thing just the first 2 chapters. i only own a physical copy. It makes extensive use of scanf and has many many typos and shit that makes the program not compile or run
>>
>>52543835 (Me)
like if you lay it out like a family tree, then each class in the "family" will inherit from exactly one parent. classes can also implement interfaces, but those interfaces do not have a family tree of their own.
>>
>>52543538

Please respond.
>>
>>52543874
>but those interfaces do not have a family tree of their own.
That's wrong if you mean inheriting other interfaces.
>>
>>52543897
a subclass inherits the interface from its parent class. there is only one "trunk".
>>
>>52543741
>a little faster getch
Are we back to conio.h DOS days?

>main()
>no return type
>no void
>claims it's updated for C11
lol
>>
>>52543924
a subclass can use other interfaces additionally and the interfaces can also inherit from multiple other interfaces
>>
>>52543932
main() is a valid signature
>>
>>52543932
that's what i'm saying and this was my first programming book and i can't believe pearson, a company i used to work for would allow having its name on such shit
>>
>>52543741
>Your computer knows 256 different characters. Each of them is found in something called the ASCII table, located in Appendix A, “The ASCII Table.” (ASCII is pronounced ask-ee. If you don’t know-ee, you can just ask-ee.) Anything your computer can represent can be a character
>>
>>52543948
1: Not in C11
2: You actually need the (void) or the signature will not be the one that the standard supports.
>>
File: screen.png (51KB, 596x656px) Image search: [Google]
screen.png
51KB, 596x656px
>>52543948
ok buddy
>>
>>52543969
void is only needed in prototypes, tard.
>>
>>52543989
Who told you this shit?
>>
File: inheritance.png (31KB, 781x1024px) Image search: [Google]
inheritance.png
31KB, 781x1024px
>>52543938
ah, didn't know that or i didn't have that in mind. still, it's not quite the same as the kind of multiple inheritance where you can derive from multiple parent classes.
>>
>>52543948
http://stackoverflow.com/a/29190987
>>
>>52543984
what am I supposed to be looking at here? it compiles fine

>return 0
kek
>>
>>52543753
>It's what started this discussion!
Are you high? What started the discussion was someone claiming that C is object oriented....

You said "MUH INHERITANCE" and I pointed out that inheritance isn't a prerequisite for being object-oriented.

>Fuck you, I'm done talking to you.
There's no need to be upset anon.

>>52543750
>you can implement multiple interfaces
And this isn't multiple inheritance how exactly?
>>
>>52543969
standards conforming and valid are not mutually inclusive

>>52544014
did you even read what you linked?
>>
>>52544040
No implementation is inherited therefore it's not multiple inheritance you fucking inbred.
>>
>>52544040
you can't inherit from multiple parent classes you dipshit.
>>
File: f3h2eqZrr.jpg (470KB, 2322x4128px) Image search: [Google]
f3h2eqZrr.jpg
470KB, 2322x4128px
>>52544018
but i get a warning for returning an int, which is what the book says you have to do at the end of every program.
just dont buy this book.
>>
>>52544048
>did you even read what you linked?
Yes
>>
>>52544062
It actually allows to get the same results.
Just needs some more boilerplate.
>>
>>52544040
>I pointed out that inheritance isn't a prerequisite for being object-oriented

http://cs.smu.ca/~porter/csc/common_341_342/notes/oop_3pillars.html
>>
Am I strange if I find Haskell to be very ugly?
Nice language but I don't get why so many people claim it is beautiful...
>>
>>52544084
you actually can't get exactly the same results without merging two parent classes into one. an interface can only have public methods and public final variables.
>>
>>52544099
Do you find ALL Haskell ugly? Like any language you can write bad code in it if you want.
>>
>>52544002
c standard, tard.
>>
>>52544118
prove it fag
>>
>>52544109
public static final variables, even
>>
>>52544124
Who exposes member variables directly in Java?
>>
>>52544090
he's right, to do oop you only need objects. inheritance is not required.
>>
File: IpsYFZC.jpg (444KB, 2322x4128px) Image search: [Google]
IpsYFZC.jpg
444KB, 2322x4128px
>scanf(" $%f")
>just find the file and double click it.
>>
>>52544131
it's perfectly fine to do it, especially final variables.
>>
File: 160315.jpg (52KB, 590x844px) Image search: [Google]
160315.jpg
52KB, 590x844px
Redpill a C++ guy on Web dev.

Do Javascript and php serve the same purpose?
What about python and ruby for Web dev? What are their use cases?
>>
>>52544115
I mean, most Haskell code I find on github... Dunno if it is so bad (I know some Haskell, but pretty basic things)
>>
>>52544099

You don't know Haskell good enough. At first it seems ugly, but at some point it'll all make sense and make debugging and refactoring so much easier
>>
>>52544185
Likely.
But still... meh.
>>
>>52544170
Not if it contains something mutable.
>>
>>52544206
Not him, but why?
>>
File: scr.png (63KB, 630x513px) Image search: [Google]
scr.png
63KB, 630x513px
>>52544123
lel, are you really this retarded ? please don't be this retarded.

pic, and there many examples in the standard with int main() {...}
>>
Blog about your day
>>
>>52544221
Because final doesn't protect the (same) object from being changed?
>>
>>52544236
Sorry, misunderstood, I don't even know what you're talking about...
>>
>>52544183
What do you find ugly about this?

map :: (a -> b) -> [a] -> [b]
map f (x:xs) = f x : map f xs
map _ [] = []
>>
>>52544123
>>52544228
also, at 6.7.6.3 Function declarators (including prototypes)

14 An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.

get #rekt
>>
>>52544228
What the fuck? This is not this PDF of the standard.
And read the stackoverflow link.
>>
>>52544289
Not him, but everything
>>
>>52544231
I spent the morning with my boyfriend and then played around with knockout.js for a bit. it's 4pm now so pretty quiet day so far. probably going to make dinner and watch some anime together in a while
>>
>>52544293
>>52544294
Not to mention that you kiddo have to still prove that main() without the int part is valid.
>>
>>52544328
That's my day expect the being awake at morning part, the boyfriend or anyone part, the js part, make dinner part (unless coffee and cigarettes count), and together part
>>
>>52544310
How would you rather it looked?
>>
>>52544328
What anime?
>>
>>52544362
>unless coffee and cigarettes count
Do you live in an ex-USSR state?
>>
>>52544231
i got so disgusted with a programming book that i decided to stop reading it even though i payed for it. Also i beat the first boss in dark souls 1
>>
File: tGKIDM8.jpg (115KB, 650x650px) Image search: [Google]
tGKIDM8.jpg
115KB, 650x650px
>>52544334
what do you not understand in

>An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.

http://www.open-std.org/jtc1/sc22/wg14/www/standards

>The latest publically available version of the C11 standard is the document WG14 N1570, dated 2011-04-12. This is a WG14 working paper, but it reflects what was to become the standard at the time of issue.

now search for
int main() {
in the standard
>>
>>52544383
Welcome to the N.H.K.
>>
>>52544328
web devs everyone
>>
>>52544401
Still waiting for you to prove that you do not need int in main.

>>The latest publically available version of the C11 standard is the document WG14 N1570, dated 2011-04-12. This is a WG14 working paper, but it reflects what was to become the standard at the time of issue.
I know that, why do you post random things?

Why haven't you read http://stackoverflow.com/a/29190987 yet? Funny you talk about damage control but you ignore everything I post, lol
>>
>>52544374
What does it even do? Define a recursive map function?
func map(f, l) {
if (l = null) {
return null
} else {
return pair(f(l.first), map(f, l.rest))
}
}
>>
What is your normal day like, /dpt/?

>Stay idle 70% of my time on the job, mostly on reddit and /g/
>The other 30% is spending my time fixing non-issues
>60k a year

Web design is where it is, gentlemen.
>>
>>52544386
Nope, Europe.
>>
File: B-boo!.png (584KB, 1000x1000px) Image search: [Google]
B-boo!.png
584KB, 1000x1000px
Stupid question, but in OCaml, how can I know for certain my function is performing tail-recursion instead of creating a bunch of stack frames? I mean I don't do anything else with the recursive call's return value, is that good enough to say it's going to be tail-recursive?
>>
File: 161017757_44042348.jpg (67KB, 590x632px) Image search: [Google]
161017757_44042348.jpg
67KB, 590x632px
>>52544444
the standard itself has main() {} in their examples, the semantics of the language rule that () and (void) are the same when it come to function definition (not a prototype). why the fuck are you still arguing ?

>stack overflow has more authority than the standard itself.
dude, you are going full retard. i don't care a shit about stack overflow, it's a refuge for mediocre programmers like you
>>
>>52544493
>He fell for the meme
>>
>>52544176
Sup, fellow CPP guy. Javascript runs on your browser, while php runs on the server.

python and ruby are shit for webdev. I don't know any cases where the python/ruby is actually better than Javascript/php.
>>
>>52544468
You honestly find that less ugly than the Haskell code? To each their own I suppose.
>>
>>52544493
use a loop
>>
>>52544501
>standard itself has main() {} in their examples
Nope, nice shiposting

>stack overflow has more authority than the standard itself.
nice try proving him wrong lol
>>
>>52544513
It has all those things that make shit readable like clear keywords, indentation, clear blocks, etc.
>>
>>52544310
what about

map :: (a -> b) -> [a] -> [b]
map f = \case
[] -> []
x:xs -> f x : map f xs
>>
>>52544501
DAMAGE CONTROL
A
M
A
G
E

C
O
N
T
R
O
L
>>
>>52544547
horrible
>>
>>52544289
ridiculously terse with no meaningful function name or variable names or anything like you have to read the entire thing to have the vaguest idea of what it does

too many fucking symbols

>>52544099
no it's one of the ugliest languages in existence
>>
File: 6Qc1svk9zc.jpg (157KB, 1920x1080px) Image search: [Google]
6Qc1svk9zc.jpg
157KB, 1920x1080px
I'm a website developer thinking of moving to game development (Still thinking what kind of game development). Any advice from any game developers? c:
>>
>>52544501
proof or gtfo
>>
>>52544564
>>52544571
map :: (a -> b) -> [a] -> [b]
map = fmap
>>
>>52544509
I've never used php, heard everyone saying that it's bad but improved with recent versions.
Ruby on rails or php?
>>
>>52544544
>Nope, nice shiposting

from 6.7.6.3 Function declarators (including prototypes)
 void addscalar(int n, int m,
double a[n][n*m+300], double x);
int main()
{
double b[4][308];
addscalar(4, 2, b, 2.17);
return 0;
}
void addscalar(int n, int m,
double a[n][n*m+300], double x)
{
for (int i = 0; i < n; i++)
for (int j = 0, k = n*m+300; j < k; j++)
// a is a pointer to a VLA with n*m+300 elements
a[i][j] += x;
}


from 6.7.6.3 Function declarators (including prototypes)
         #include <stddef.h>

size_t fsize3(int n)
{
char b[n+3]; // variable length array
return sizeof b; // execution time sizeof
}
int main()
{
size_t size;
size = fsize3(10); // fsize3 returns 13
return 0;
}
>>
>>52544133
No, you only need polymorphic messages.
>>
>>52544493
If it's a tail call then it's tail recursive :^)
>>
>>52544581
sounds like you're too retarded to make a proper game you should just give up and use a babby engine like unity and go to >>>/vg/agdg
>>
>>52544593
PHP (imo)
>>
>>52544581
C++
>>
>>52544547
what does a name at the beginning of a line mean?
what does "::" mean?
what does "->" mean? return? why is it chained? is that some currynigger shit?
what do a and b mean in that position?
what do the brackets mean?
what does f mean in that position?
why the hell is there a backlash?
what do the brackets mean?
what does x and xs mean?
what does the colon mean?
what does the other colon mean?
how is case terminated?
>>
>>52544594
>int main()
nice back-pedalling, it's not main() {} (something that you were supposed to prove that the standard allows)
>>
>>52544547
disgusting

>>52544592
still disgusting
>>
>>52544606
It 'sounds' like you're too socially awkward to go outside so you should just keep doing what you're doing and don't give up. <3

>>52544610
I'll check it out!
>>
>>52544493
If you don't sequence operations after the recursive call, then it's a tail-call.
>>
>>52544546
>clear keywords, indentation, clear blocks, etc.
The code is so short it doesn't need keywords or indentations. One could say your code isn't readable as it has zero type information, something which is essential in statically typed languages.

If you wanted you could write it as this:
map func list =
if null list then
[]
else
head list : map func (tail list)


Colon in Haskell is analogous to cons in other languages.
>>
>>52544622
#include <stdio.h>
int main(int argc, char** argv) {
printf("hello world!\n");
}

What does int mean?
What does a name between int and parentheses mean?
What does () mean?
What does #include mean? Import? Why is the file in brackets? Is that some template shit?
What do " and \ mean in that position?
What do the semi-colons mean?
What does f mean in that position?
Why the hell is there a backslash?
What do the semi-colons mean?
What does argc and argv mean?
What does the star mean?
What does the other star mean?
How is main terminated?
>>
>>52544581
>reddit meme
>c:
>webdev
my advice for you is to first fuck off, then die
>>
>>52544713
make sure you fuck off first
>>
File: 1445490144309.jpg (306KB, 992x767px) Image search: [Google]
1445490144309.jpg
306KB, 992x767px
>>52544538
But I want to be hip and cool.

>>52544663
Hmm, okay I was wondering if there was a way to test it, but I guess that will have to do.
>>
>>52544571
https://en.wikipedia.org/wiki/Map_(higher-order_function)

I'm not sure what name would be more meaningful than map when it's a commonly used term.

In mathematics f is a commonly used to denote a function, and x is commonly used to refer to a variable a function is applied to. Since (x:xs) splits it into a head and tail, xs is literally a group of x (pronounced eccses).

Objectively I don't see how it's that terse when you spend a little time getting to know the language. Nobody is going to understand mathematical notation without learning it, so why should it be any different with Haskell? A little learning goes a long way.
>>
>>52544493
first search on google
https://cseweb.ucsd.edu/classes/sp15/cse130-a/static/tailrecursion.pdf
>>
What's the best Java book for someone with around 3 years of experience? Started with Head First Java which was okay, but I'd like a decent book now to continue developing my skills.
>>
A lot of you guys have legit autism.
>>
>>52544674
you could just as well do something like
list(T) func map(T func(T) f, list(T) l)


and your example is still kinda shit - function calls without parenthesis are disgusting and who the hell uses brackets for lists?
>>
>>52544748
so you're programming essentially a glorified math expression

what are you going to use it for?
>>
>>52544176

Python, ruby, node.js (JavaScript), php are used for the back end (servers)

JavaScript runs in browsers (front-end, client side) and can interact with the DOM to bring about behavior.

Don't listen to the memes about what is bad and what is good. Everything is a tool and it comes down to personal preference and what you want to do.
>>
>>52544804
and a lot of you webkeks will never make a commercial game unless you use a hand-holding tool like unity to make some shitty youtube bait to put on steam greenlight
>>
>>52544809
Only absolute beginners program their own map, it's already built into every functional language.
>>
File: bower.json.jpg (105KB, 394x700px) Image search: [Google]
bower.json.jpg
105KB, 394x700px
>>52544821
Node is also the fastest by a mile.
>>
>>52544834
map in OCaml is not tail rec.
>>
>>52544735
>Hmm, okay I was wondering if there was a way to test it, but I guess that will have to do.
I'm not sure why you would want to do that but you could just run GDB to see that the tail calls are optimized if you don't believe it.
>>
>>52544842
Then OCaml is garbage.
>>
>>52544842
Nobody uses the default standard library in OCaml because it is not meant for actual use, it is the minimal set of operations required to build the compiler. That's why Core exists.
>>
>>52544798
Effective Java, perhaps?
>>
>>52544859
>Core
>30MB executables after running GNU strip
choose both
>>
>>52544622
>what does a name at the beginning of a line mean?
That's the name of the function we are defining.

>what does "::" mean?
"Has type" as in, "map has type..."

>what does "->" mean? return? why is it chained? is that some currynigger shit?
Yes, it's currying. It simply means what's on the function takes what's on the left of the arrow and returns something that takes what's on the right. That's why the last item can be seen as the return type, as it cannot be applied to anything else.

e.g.
add :: Int -> Int -> Int
add x y = x + y

addOne = add 1 (has type of Int -> Int)
two = addOne 1 (has type of Int)


>what do a and b mean in that position?
They are variables, they can be any type possible such as Int, Bool, etc.

>what do the brackets mean?
A list.

>what does f mean in that position?
It's an argument to map of type (a -> b)
>>
>>52544909
>being this dumb
>>
File: run.gif (13KB, 84x62px) Image search: [Google]
run.gif
13KB, 84x62px
Would anyone mind posting the programming challenges for their kouhai? thx doc
>>
>>52544807
>function calls without parenthesis are disgusting
Subjective. Writing f(x) is valid Haskell if you are so inclined.

>who the hell uses brackets for lists?
Many languages. Though similar but not the same, mathematics uses brackets for matrices.
>>
>>52544707

PART 1/2

C++ wizard

>What does int mean?
Int means that the function retuns an integer.

>What does a name between int and parentheses mean?
the name of your function

>What does () mean?
It shows what your function receives from outside.

>What does #include mean? Import? Why is the file in brackets? Is that some template shit?
It means it imports important common functions in order to you dont have to actively put them on your code. The file on brackets is one f the standards In-Out header of functions.

>What do " and \ mean in that position?
" " mean the start and end of your string. \ doesnt mean anything by itself, but with n (\n) it makes the string go to the next line.

>What do the semi-colons mean?
They mean the end of a command.

>What does f mean in that position?
Nothing. Printf is a function that was inheretid from the stdio.h you included in the header.

>Why the hell is there a backslash?
Read the answer above.

>What do the semi-colons mean?
Read the answer above.

>What does argc and argv mean?
They give the programmer access to the command prompt where the program was called. argc is an integer and argv is a vector.

>What does the star mean?
Read above.

>What does the other star mean?
Read above.

>How is main terminated?
A function is written within brackets { }.
>>
File: Bait.png (220KB, 387x545px) Image search: [Google]
Bait.png
220KB, 387x545px
>glorified math expression
If I had a nickel
>>
>>52544983
This is the dumbest post on 4chan currently. Congrats. Haven't seen someone be this wrong in a while.
>>
2/2

Haskell faggot
>what does a name at the beginning of a line mean?
LIKE WHAT? DIDNT YOU TAKE MATH 605 TO KNOW THAT?

>what does "::" mean?
HAHA, I KNOW IT AND YOU DONT

>what does "->" mean? return? why is it chained? is that some currynigger shit?
IT GIVES YOU SOMETHING, LIKE I GAVE YOUR MUM AIDS LAST NIGHT

>what do a and b mean in that position?
NEURAL COMPUTATIONAL STIMULI

>what do the brackets mean?
YOU WANNA START SOMETHING AND END SOMETHING? THAT IS WHAT THE BRACKETS ARE FOR

>what does f mean in that position?
IS THE NAME OF THE FUCK YOU WANNA MAKE

>why the hell is there a backlash?
IF YOU DONT KNOW YOU DONT DESERVE TO KNOW

>what do the brackets mean?
DIDNT I JUST SAY TO YOU?

>what does x and xs mean?
XIR AND XISS

>what does the colon mean?
THE COLON CANCER YOU GAVE ME

>what does the other colon mean?
THE AIDS

>how is case terminated?
>HE DOESNT INDENT HIS CODE
>>
>>52544863
I've heard good things about Effective Java. I'll check it out, thanks man!
>>
>>52544972
>Subjective. Writing f(x) is valid Haskell if you are so inclined.
Doesn't even have to f(x), (f x) would be fine too
>Many languages. Though similar but not the same, mathematics uses brackets for matrices.
The most similar concept from math to lists would be tuples so use parenthesis
>>
who coq here?
>>
>>52543233
>let
>>
>>52544074
You get a warning because you haven't fucking declared what the return type is.
>>
>>52545074
It understands induction proofs? Neat.

But that's barely programming at this point.
>>
>>52545074
Sorry I don't swing this way. It's perfectly cool with me that you're a homo though.
>>
File: ey.jpg (4KB, 180x180px) Image search: [Google]
ey.jpg
4KB, 180x180px
>>52543959
>mfw 0.499999999999999999 is a character
>>
File: 1453068998593.png (507KB, 595x639px) Image search: [Google]
1453068998593.png
507KB, 595x639px
>>52545115
>induction proofs are barely programming
>>
>>52545095
every language should have a let equivalent. Most do infact, besides Java. Hard luck Prajeet.
>>
>>52543116
>NO OPERATOR OVERLOADING
Doesn't Java have something like
System.out.println("Hello " + "World");
>>
>>52545160
It's called variable definition.
>>
>>52545139
>induction proofs are programming
I'm sorry but just because it uses recursive data structures doesn't make it programming.
>>
>>52545170
'let' is type inferred and immutable Prajeet.
>>
>>52545184
Coq is hardly programming, I agree. But induction proofs are programming.
>>
>>52545064
Haskell has a tuple type.

main = print(length(1.0, 2.0))

length :: Floating a => (a, a) -> a
length (x, y) = sqrt(x^2 + y^2)


Does it still look ugly?
>>
>>52545234
>Does it still look ugly?
extremely
>>
>>52545184
>>52545208
I don't mean that doing an induction proof necessarily means you're programming something. But you can program something by writing an induction proof.
>>
>>52545248
What's wrong with it? If it's the type signature then what about now?

main = print(length(1.0, 2.0))

length (x,y) = sqrt(x^2 + y^2)
>>
head fibs = 0
head (tail fibs) = 1
tail (tail fibs) = zip _+_ fibs (tail fibs)
>>
>>52545272
still ugly with that mixing of the parameters into the assignment.
that's nicer in scheme (even with the short-hand)
>>
>>52545325
>assignment
It's called definition.
>>
>>52544142
>Assuming user will input dollar sign

How did this get published? Actually nvm, what publishers even know the difference between programming and markup languages.
>>
>>52545342
then don't use the classical assignment (or equality) operator
>>
>>52545325
That's how most languages do function definitions.

float length(float x, float y)
{
return sqrt(x*x + y*y);
}


In fact, write it all on one line and change the opening brace to an equals sign, and you have something that looks very similar to the Haskell version.
>>
>>52544176
>http://php.net/manual/en/types.comparisons.php
>(array() == NULL) returns true

Absolutely disgusting.
>>
>>52545377
And it looks retarded when you use "="
give me my (define (length x y) ....) dammit
>>
>>52545356
Classical according to whom? ALGOL used := for assignment.
>>
>>52545356
But it IS equality.
>>
>>52545395
You really prefer:
(define (foo x y) (+ y x))

to
foo x y = y + x

?
>>
>>52545398
and "=" for equality not definition.

>>52545418
yes, very much
>>
>>52545428
Definition IS equality.
>>
>>52545439
No, it really isn't.
>>
>>52545460
How is it not?
>>
>>52545166
No user-defined operator overloading. String concatenation is an exception to this.
Really they should have used ".." or anything else, so as to not confuse people in examples like "2" + "5" returning "25".
>>
>>52545466
Because equality describes (that doesn't have to be true)) a relationship, a definition defines things.
>>
>>52545516
>that doesn't have to be true
???
>>
>>52545395
are you math illiterate or something ? = made sense, especially when procedures are first class values.

foo x y = x + y
bar = foo
>>
>>52545516
Equality is quite a bit more complex than you think.

Propositional equality can be true or false.

Definitional equality is a judgement that something means the same thing as something else. A proof of propositional equality can be derived from definitional equality -- it is always true.

Both are different forms of equality, but unfortunately they tend to use the same symbol in mathematical notation. Not in programming, though -- definitional equality is usually written (x = y) while propositional equality is usually written (x == y).
>>
>>52545516
>>52545657
And before you bring up "but the assignment operator", assignment is basically the same thing as definition in a single static assignment language like Haskell (or mathematics in general).
>>
>>52545516
What about intensional equality?
>>
what's the easiest (or most efficient) way to send events between languages?

Like from javascript to java
>>
>>52545727
Sockets.
>>
>>52545744
yeah that's what I was thinking
ok then
>>
>>52545727
you can hook between JavaScript and most languages. basically you can host a JavaScript runtime within Java and invoke methods in it and subscribe to events from Java
>>
>>52544176
In addition to >>52545386

>Note that php comparison is not transitive:
>"php" == 0 returns true
>0 == null returns true
>null == "php" returns false

Sometimes the memes are real. Don't use PHP.
>>
i tried to copy this code to play with but in java

https://www.youtube.com/watch?v=MqZgoNRERY8

http://txti.es/bitshiftvariationsincminor

i copied this from the comments but i'm guessing it's incorrect because it works fine mostly but in certain parts there's a horrible noise and then it goes back to normal etc.

help pls

# include <stdio.h>
char* notes1 = "BY}6YB6%";
char* notes2 = "Qj}6jQ6%";
int getNote(int volume, int mask, int octave, int instrument){
int selection = 3 & volume >> 16;
char* selected = selection ? notes1:notes2;
int baseNote = selected[octave % 8] + 51;
int note = (baseNote * volume) >> instrument;
int result = 3 & mask & note;
return (result << 4);
}

int main(){
for(int i=0;;i++){
int n = i >> 14;
int s = i >> 17;
int ins1 = getNote(i, 1, n, 12);
int ins2 = getNote(i, s, n^i>>13, 10);
int ins3 = getNote(i, s/3, n + ((i>>11)%3), 10);
int ins4 = getNote(i, s/5, 8 + n -((i>>10)%3), 9);
int combined = ins1 + ins2 + ins3 + ins4;
putchar(combined);
}
}
>>
>>52545657
>Both are different forms of equality, but unfortunately they tend to use the same symbol in mathematical notation.
Since when? You use ":=", or "=" with a little def on top.
>>
>>52545862
here's what i have in java

    static volatile boolean exit;

public static void main(final String[] args) throws LineUnavailableException {
final int bufferSize = 2048;
final AudioFormat audioFormat = new AudioFormat(44100, 8, 1, true, false);
final DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, bufferSize);
final SourceDataLine soundLine = (SourceDataLine) AudioSystem.getLine(info);
soundLine.open(audioFormat, bufferSize);
soundLine.start();
final byte[] buffer = new byte[bufferSize];
new Thread(new Runnable() {
short foo;
short bar;
final short[] a = { 0, 771, 34, 1235, 4112, 373, 9600, 82 };
final char[] notes1 = "BY}6YB6%".toCharArray();
final char[] notes2 = "Qj}6jQ6%".toCharArray();

int getNote(final int volume, final int mask, final int octave, final int instrument) {
final int selection = 3 & volume >> 16;
final char[] selected = selection != 0 ? notes1 : notes2;
final int baseNote = selected[octave % 8] + 51;
final int note = baseNote * volume >> instrument;
final int result = 3 & mask & note;
return result << 4;
}

@Override
public void run() {
int i = 0;
while(!exit) {
for(int j = 0; j < bufferSize; j += 4) {
++i;
final int n = i >> 14;
final int s = i >> 17;
final int ins1 = getNote(i, 1, n, 12);
final int ins2 = getNote(i, s, n ^ i >> 13, 10);
final int ins3 = getNote(i, s / 3, n + (i >> 11) % 3, 10);
final int ins4 = getNote(i, s / 5, 8 + n - (i >> 10) % 3, 9);
final int combined = ins1 + ins2 + ins3 + ins4;
buffer[j] = (byte) combined;
buffer[j + 1] = (byte) combined;
buffer[j + 2] = (byte) combined;
buffer[j + 3] = (byte) combined;
}
soundLine.write(buffer, 0, bufferSize);
}
}
}).start();
final Scanner s = new Scanner(System.in);
s.nextLine();
s.close();
exit = true;
}
>>
>>52545872
f(x) = 2x + 1
>>
>>52545882
special short-hand for functions, not really a proper definition
>>
File: John Carmack Office.jpg (134KB, 1183x770px) Image search: [Google]
John Carmack Office.jpg
134KB, 1183x770px
I'm making a python program that reads from a text file within the same folder. All is good as long as i run the program with a terminal "located" in the same folder. But whenever i specify the path to the file "python path/to/file/python.py", i get a traceback error saying that it couldnt find the file that the program is reading from.

How do i set the path to the file in the python code so that i can fix this error?
>>
File: Carmack Ferrarri.jpg (90KB, 677x675px) Image search: [Google]
Carmack Ferrarri.jpg
90KB, 677x675px
>>52546030
I'm using
calObj = open(fileName, 'r') #Opens and reads the calendar files
line = calObj.readlines()


To read from the file
>>
>>52546030
You can't unless you take the file name as an argument to your program.
>>
File: fuck all this shit.jpg (37KB, 585x307px) Image search: [Google]
fuck all this shit.jpg
37KB, 585x307px
>>52544142
>gets()

Seriously? A book published in 2013 (according to Amazon), claiming to do C11 uses gets()? No. This shit is unacceptable.

This book should be terminated and its author should publicly apologize for this travesty and then he should be tarred and feathered.

>getchar()
We DOS now.
>>
Is this thread like /sqt/ for programming or not?
>>
>>52546134
You can try.
>>
>>52546134
It's not meant to be, but nobody does any real work around here so sure, why not.
>>
>>52546115
What is wrong with getchar? I think you are confusing it with getch.
>>
File: ajr.png (80KB, 669x350px) Image search: [Google]
ajr.png
80KB, 669x350px
Scraping trip reports from a forum. Going to make them searchable by substance, age etc. Shit gonna be dope.
>>
>>52546211
I could be, yes. It's been many years since I've used those functions, I usually just give my programs all the data they need through CLI args or files, I don't wait for keypresses.
>>
>>52543959
the first two chapters tell you to install codeblocks and that it is a compiler, and how to use it (but not that you need an actual compiler for it to compile anything)
>>
>>52546176
>>52546166
So I'm learning C and there is a new funktion atoi (ascii to int), but it doesn't work and I don't know why. I have an array "char input[80]" tht should change a text to number (int type) "int result"

The book says:
result=atoi(input);

But the problem here is that it shows me always the number 0 and I don't understand why.
>>
>>52546275
>or files
You do use (f)getc then, right?
Also, you can still do that with getchar if you have externally redirected the stdin or changed it with freopen.
>>
>>52546317
>and there is a new funktion atoi
It is not new, and it should be avoided. Use strtol instead.

>ascii to int
No, this is not what it does at all.

>The book says:
What book are you using?

>But the problem here is that it shows me always the number 0 and I don't understand why.
Show us your whole code. You are probably giving it the wrong input.
>>
>>52543345
Only look in one direction, e.g. start at the beginning, and only compare to items to the right.
items = [whatever];
links = [];
for i = 0 to items.length-2
for j = i+1 to items.length-1
links.push(create_link(items[i], items[j]);
end
end
>>
>>52546346
How can I post a code on /g/ like him?
>>52545875
>>
>>52546381
Read the sticky/faq
>>
>>52546381
Premium account.
>>
>>52546317

#include <stdio.h>
#include <stdlib.h>

int main()
{
char input[80]="123";
int test = -1;
test = atoi(input);
printf("%d\n", test);
return 0;
}


this worked fine.
>>
>>52546381
Type in
[quote ]
without the space
>>
>>52543233
>let
>try let

oh god, this is meymeys isn't it?!
>>
>>52544074
>return(0);

Jesus christ
>>
>>52546454
return is a function
>>
>>52546317
>>52546346
>It is not new, and it should be avoided. Use strtol instead.
atoi is fine if you don't need anything other than base 10.

>>ascii to int
>No, this is not what it does at all.
That is literally what aoti is short for, ASCII to int

>Show us your whole code. You are probably giving it the wrong input.
atoi will only ever return 0 if the first character it finds is not numeric. It won't skip letters until it finds a number, the number needs to be first.
If you need to search for the integer inside a string, use scanf.
>>
File: 1451683583776.gif (2MB, 400x600px) Image search: [Google]
1451683583776.gif
2MB, 400x600px
What are some good challenges to learn Haskell with?
>>
>>52540853
I love how people think they will get any warning before a raid happens.
No, the police don't speed to your house with full sirens.
No, the police don't check if you're home.
They raid you at 4am while you're most vulnerable to make sure you don't flee or smash your hard drives.
>>
File: Untitled.png (3KB, 220x243px) Image search: [Google]
Untitled.png
3KB, 220x243px
wat do
>>
>someone posts Coq and not Agda
>half the thread about someone not liking how something looks with 0 understanding of it

come on guys
>>
>>52546493
Do you want 5 line fizzbuzz shit to feel good about yourself or do you want to write something useful?
>>
Currently browsing the web for publications about 2D/3D point cloud algorithms.
I am programming to prepare for my computer vision exam.

Also it would be nice to have a little package in the end that I could use for dogfooding.
>>
>>52546499
That argument wasn't about Coq, it was about Haskell.
>>
>>52546492
>atoi is fine if you don't need anything other than base 10.
How about error checking? Oh right...

>That is literally what aoti is short for, ASCII to int
This is the first time I hear that, but even then, this is not what it does.

>atoi will only ever return 0 if the first character it finds is not numeric
Or if the string is 0.
>>
>>52546528
My points were about two different topics.
>>
>>52546496
Make an analog clock.
>>
>>52546532
Okay.
>>
>>52546381

>>52546389
>>52546395
>>52546427
No need to be unhelpful faggots.

(code)Copy and paste the code inside these blocks like where this sentence is (/code)

But use square brackets [] instead of ()
>>
>>52546531
>>atoi will only ever return 0 if the first character it finds is not numeric
>Or if the string is 0.
Zing.
>>
>>52546553
How is that unhelpful? Kill yourself.
>>
>>52546553
cuck
>>
>>52546553
AYYYY WHITE KNIGHT FAGGOT
>>
>>52545377
>In fact, write it all on one line and change the opening brace to an equals sign
It would look like BCPL.
http://xeroxalto.computerhistory.org/Indigo/AltoSource/CMDSCANSOURCE.DM!3_/.Keyword.bcpl.html
>>
>>52546402
>>52546346
#include <stdio.h>
#include <stdlib.h>

main()
{
int result,number;
char input[80];

printf("\nplease write in: ");
gets(input);
result=atoi(input);
printf("the result is %i\n",result);

printf("\nplease write a number : ");
scanf("%i",&number);
sprintf(input,"%i",number);
printf("the string reads as follow %s\n",input);
}



>>52546346
>It is not new, and it should be avoided. Use strtol instead.
How to use it?
>No, this is not what it does at all.
Book says that it changes numbers of text forms into "numerical" types (int)
>What book are you using?
A popular German book for C beginners which was also recommended by my professor, but some people in the online reviews say he is often wrong in the book.
>Show us your whole code. You are probably giving it the wrong input.
hope I did right

Both atoi and sprinf don't do what the book says.
>>
>>52546553
thanks, but found it in the sticky already
>>
NEW THREAD!

>>52546613
>>52546613
>>
>>52546632
dumbass
>>
>>52546632
Dumbass
>>
File: Untitled.png (3KB, 243x243px) Image search: [Google]
Untitled.png
3KB, 243x243px
>>52546537
why
>>
>>52546531
>>52546559
Fucking hell, I meant to remove "only ever", obviously it returns 0 for "0".

>How about error checking? Oh right...
It returns 0 if there is an error. It might also return 0 if there is not an error, but it finds "0". If you expect to come across a lot of "0"s then don't use atoi, otherwise it's fine.

>This is the first time I hear that, but even then, this is not what it does
It's not called "ASCII values to int", just "ASCII to int". That is what it does, it converts the ASCII representation of a number to an int.
If it wasn't ASCII to int, then it would read the byte values so atoi('!') would give you 33, rather than 0.
>>
>>52546496
Make a bot for 4chan that understands commands like an IRC bot does.
Use Googles OCR library to bypass the captcha.
>>
>>52546613
>>52546613
>>52546613
>>52546613
>>
>>52546612
That book is bad. Consider getting something like "C Programming: A Modern Approach, 2nd Edition".

Here are the problems I notice:
- no return 0 (not needed for C99+ but this book is not about C99)
- use of gets (removed from the language and extremely dangerous)
- atoi instead of strtol
- heavy use of scanf
- usage of sprintf without reason
- main() instead of the modern int main(void)

In this example, assuming that you entered the correct input (an integer and then enter without anything else) should normally work.

>>52546680
C does not force the usage of ASCII, another encoding may as well be used and atoi will still work just fine. It has nothing to do with ascii.
>>
>>52545875
alright the problem was that there was seemingly no audio format for my system with PCM_UNSIGNED at least for 8/16 bits per sample so i "fixed" it by halving the volume so that the samples don't overflow
>>
>>52546726
>C does not force the usage of ASCII, another encoding may as well be used and atoi will still work just fine.
I never said it was forced. This is, however, what it was named after: http://stackoverflow.com/questions/2909768/where-did-the-name-atoi-come-from

>It has nothing to do with ascii.
It did when it was named, things may have changed since then, but the name stuck.
>>
File: why-would-you-do-that[1].jpg (82KB, 292x302px) Image search: [Google]
why-would-you-do-that[1].jpg
82KB, 292x302px
What's the point of declaring but not defining a function before the main function, then defining the function after the main function? I can't read that shit. I'm like reading top to bottom and main() is calling functions that I have no idea about what they do unless I skip down to the bottom and read that shit and then try to find my place and whatnot.
>>
>>52546726
Yeah it's a book from the early 90s, but an edition for 2014 and our professor is an oldfag with cancer.

Why is gets dangerous?

sprintf should just show us the opposite (prints your input to array which you can change to a text with sprintf)

>main() instead of the modern int main(void)
Yes, the book says it changes the functions automatically to int if you don't declare it as something other, but the void is new. I will use it in the next time.
>>
>>52546862
main is better at the top imo
>>
>>52546870
>Why is gets dangerous?
Because it reads characters into an array without knowing its size. It can in turn if the input is big enough overwrite memory you did not want it to.
>>
>>52544707
Now with real answers. I had no idea C++ at this level could be confusing... at all...

>What does int mean?

It's a data type integer that allows numbers to be stored and parsed when needed.

>What does a name between int and parentheses mean?

"main" is the primary function in a c++ program. It's the control center of your program where all external functions can be called. The main function can also act as a function where you can put logic as need for small programs.

>What does () mean?

In a function declaration, the parentheses are where you pass variables to be used inside of the function. In this case it's argc and argv which pertain to arguments given when executed in the command line.

>What does #include mean? Import? Why is the file in brackets? Is that some template shit?

Include is how headers and libraries are linked to cpp files. They "include" functions defined in other files like the printf function is defined in <stdio.h> which is why that include exists. The <> notation is just how c++ reads headers.

>What do " and \ mean in that position?

the quotations inside the printf function indicate a string of chars which printf requires
int printf( const char* format, ... );
. The backslash followed by n indicates a newline. The backslash used as a char can represent a lot of text functions like newline, return carriage, tab, etc.

>What do the semi-colons mean?

It delimits a completed expression. Where you place semicolons becomes intuitive once working with the language just a little bit.

>What does f mean in that position?

printf stands for print formatted data.

>Why the hell is there a backslash?

When tied with n it means newline. See above.

>What do the semi-colons mean?

You asked this twice retard.

>What does argc and argv mean?

See the parentheses question
>>
>>52544707
part 2

>What does the star mean?

The double star is used in code very rarely but shows up in c++ commonly. It means a pointer to a pointer. It would take a long time to explain this if you're coming from babby python. A single star would mean just a pointer.

>What does the other star mean?

look above m8

>How is main terminated?

Main should be terminated with
return 0;
or some other number since the main function is defined as an int type. A lot of times (err... all the time) the compiler assumes return 0 in the main function.
>>
>>52546862
forward declarations let your compiler know that a function/variable/enum/struct exist somewhere in your code but hasn't been defined yet.

It's great for when you're writing lots of small, but tightly interconnected functions that call each other or themselves
Otherwise, the compiler thinks you're calling undeclared functions and returns an error.

also, good coding practice has your putting your main function at the bottom, because it's only purpose is to start your program loop and exit if the program loop encounters break; somewhere
>>
>>52546921
Yeah the guy in the online review wrote this, too.
Thanks for the help. I hope I can find your recommended book somewhere.
>>
>>52546968
I mean why not declare AND DEFINE your functions at the top and then have your main?
>>
>>52547019
sometimes it's easier to visualize
but really, it makes more sense for structs
eg...
struct _obj_vtable;
struct _obj;

struct _obj {
int *data;
struct _obj_vtable *vt;
};

struct _obj_vtable {
void (*func1) (struct _obj *self);
void (*func2) (struct _obj *self);
void (*func3) (struct _obj *self);
};


In this case, both structs need to know that the other struct exists, otherwise, you get a compile time error.
>>
>>52546862
There are two ways to look at it.

Yes, any function that main uses needs to be declared before main itself, otherwise the compiler shits the bed.
Yes, you could just put main at the bottom of the file, with every other helper function first.

But main is still executed before any other function, so if you order the definitions in order they are actually used, main would be first.
Also, if you have a lot of obvious functions that do mundane things, putting main below them is almost hiding away the actual program.

That said, I do usually put main() at the bottom in my own code, but I can see why people might prefer it closer to the top.
If anything, it's just more consistent with OOP languages where you tend to put the class definition right at the top.
>>
>>52546612
I sure enjoy writing code that my compiler gives 3 errors in!
Thread posts: 321
Thread images: 31


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.