Learning how to program

I've been reading K&R and I was told to read "SEI CERT C Coding Standard" afterwards, but while I may learn C from K&R, I won't be taught programming.

What's a good book for actually learning how to program? Something in C would be nice but not necessary.

Other urls found in this thread:

ccs.neu.edu/home/matthias/HtDP2e/
mitpress.mit.edu/sicp/
learnxinyminutes.com/
rosettacode.org/wiki/Rosetta_Code
daniweb.com/programming/software-development/threads/440954/can-t-fix-error-in-my-program
ioccc.org/2013/misaka/
ioccc.org/
erlang.org/doc/programming_examples/bit_syntax.html
twitter.com/NSFWRedditVideo

It has become a meme here, but SICP is quite good (free). There's also this, which is perhaps a little easier.
ccs.neu.edu/home/matthias/HtDP2e/

The latter uses Racket, which is what I'd also recommend using for the first test. Once you understand the concepts, learning another language is quite easy.

SICP: mitpress.mit.edu/sicp/
I'm sure there are more "modern" approaches in Python and Javascript, but I'm not familiar with them.

I wonder what you think "programming" is?

But that book already teaches you how to program.
Maybe SICP then is what you're looking for or some algorithm books.

SICP is awful and will fill your head full of bad ideas that will take years to unlearn.

The best way to learn to program is to throw yourself at the code again and again until you know what mistakes you are making and you know how to avoid them. These aren't books, but they'll help a lot:

learnxinyminutes.com/ : Quick rundown of a programming language
rosettacode.org/wiki/Rosetta_Code : Different programming problems solved with different languages, so you can compare the answers
daniweb.com/programming/software-development/threads/440954/can-t-fix-error-in-my-program : What not to do. Ctrl + f the phrase "new averaging system" for a laugh
Switch statements: A simple feature that solves problems that otherwise require a fuckton of if statements. It makes code like pic related a lot more tolerable although it's not the only thing wrong in the pic
Human Resource Machine: A game about programming. Teaches data structures and algorithms really well, but it's a bit on the easy side if you know what you're doing. If there's one thing to try here, it's this

If you do the exercises in K&R, you'll learn a lot, m8. After that, try to reproduce simple coreutils like cat.

Care to explain why? I am interested in going through the book at some time in the future. Should I instead read other books about algorithms and data structures instead?

SICP is a fine book, ignore that fool.

What you sound like you want to learn from a book is something you learn from doing. The book shows you the path, but you have to walk it.

memory unsafe
data races
undefined behavior

K&R C assumes that you are already familiar with the concepts of programming (what are variables, loops, functions, and why do we have them?). If you need to get yourself into the mindset first you should look for a different book.

SICP got name-dropped here, and I agree that it is a very good book that anyone should read through (and do the exercises!), but it uses Scheme and is very far removed from the metal, whereas C is very close to the metal. It will also teach you a style of programming very different from what you would do in C; for example, in C mutating variables (changing their value) is something you do all the time, but in SICP the first two chapters (two thirds of the book) have no notion of mutation whatsoever. The first chapter is all about functional programming, a paradigm which is not possible to do in C. The lessons in SICP are all applicable to any programming language, but you might have to adapt the way you think instead of simply changing the syntax a bit.

Se this post anons ?
This is why rustaceans can't have freedom.

And how do you expect that new programmers will learn about concepts you listed? By reading your posts without experiencing problems themselves? Or are we just gonna pretend that those don't exist? At some point you'll have to realize that there is no special voodoo magic going on inside your computer. C is a great way to ease in to low level concepts. You shouldn't be ignorant of what is going on behind the scenes and have at least a basic understanding of inner workings of a computer.

c is absolute garbage. c is not great for anything. c is never the right tool for any job.
someone who wants to learn programming shouldn't start with a badly designed language.
someone who wants to learn low level concepts should learn assembly.

/*[*/#include// #include//]++++[->++[->+>++++[->+>++[-]+bad/bbda"};static int S(){return(o[p][q]);}static/**/int/**/Z=0 ;void/**/z(int// l){if(/**/Z-l){Z=l;q++;if(p

Is that true? If so, it's the most beautiful thing I've ever seen.

But wait there is more:
Not only can the program output longcat can also concatenate files vertically (like "cat" command) and horizontally. Using program itself you can stack together original program source together to control length of longcat or if you stack it horizontally you set the width of longcat. To find out how many misakas have you stacked together you can feed concatenated program into brainfuck interpreter to get an overview of how many misakas have you stacked.
ioccc.org/2013/misaka/

More interesting C programs at ioccc.org/

thats a very short longcat

I had to cut it as post was too long.

...

Let Us C is pretty good, for beginner programmers

shit taste m8, use 90S2313! No adc or other useless crap.

...

The main thing is to get lots and lots of practice. Try some of the exercises on /r/the_daily_programmer.

Eh, it will teach you the concepts pretty well, as well as why you never want to do functional programming again.

SICP is garbage made to scare away newfags, ignore people that recommend it. It might be useful for seasoned programmers but for a novice that is trying to get an actual output and learn an actually useful language, its worth nothing. Its also terribly structured.
I wish I could recommend something but I have had yet to come across a useful book. My best guess is to just picked a language you like (in your case, C) and try to write simple programs. Look something up if you dont know how to do it and slowly develop your skills.

If you're fairly bright, SICP is hard to beat (this is what MIT taught their freshman students), if you're more of a mediocre person like , then it's probably best to stick to some easier python materials.

SICP is garbage even at an intermediate level. Almost all of it is teaching you to think about problems in ways that computers do not. There's really no value to this as you'll learn much faster how to write useful software by learning how computers want to work instead of how to map a meme language to some approximation of them to satisfy mathfag autism.
Worse are the insufferable faggots that claim this is a good programming book. Imagine a Structure and Locomotion of Bicycles book which creates a mathematical language around riding a bike and a bunch of anons lying in a jumbled pile of bicycles recommending it to onlookers as the best way to learn to ride a bike.

mfw.

How much of the software you use was written by mathematicians? In the extremely rare case we get a mathfag programmer who can actually accomplish something, they tend to go berserk and murder everyone like Hans Reiser. The only mathfag programmer I know IRL is obsessed with taking pictures of sluts dangling off of ledges or being held underwater and I fully expect to hear he's a serial killer someday.

You're confused about what is SICP. SICP is about the structure and interpretation of computer programs. SICP isn't about the structure of computers. You are confused and this is why you judge SICP for things that it never intends to do.

Amazing. Truly you are a master of computers.

I judge it as a first year CS book that makes students less able to write good software. I wouldn't let them read it, most schools agreed and didn't make it part of the syllabus, and MIT has even dropped it. It was a mistake.

Don't be jealous, qt. Get to work.

You are correct in that SICP is an introductory CS book. However, you seem to believe that the purpose of computer science is to teach people to write computer software. This is a mistake as computer science is not a course whose intent is to train software engineers. SICP has no intent to teach people to "write good software". The intent of SICP is to introduce people to fundamental computer science lessons.

Having non mathfags start programming was a mistake. The only way computer security is ever going to be accomplished is with theorem provers .

The Jews really got you good didn't they, user? Keep telling yourself this when you have your $100k piece of paper in hand and are literally the CS Grad meme bombing fizzbuzz in interviews.

Mathfags never get anything done. Go look at the Haskell community, they're all over it and they don't do shit.

That's because it's hard to do things right. You may be able to do things rapidly but what use are they if they are not secure or predictable. There is no such thing as provably secure computing because no one wants to put in the time to do it, not because it's impossible. If the mathfags who never get anything done could establish a bedrock of well designed and reasoned software non mathfags might be able to develop secure software more easily on top of that. But, as it stands there is an entire industry built around the fact that modern software seemingly has an infinite number of bugs and the way to deal with this is to squash them one by one, not stop the terrible practices and software that lead to the bug infestation. Doing shit wrong is only better than not doing shit at all when money is involved.

You're never going to have bug-free software, user. Just like mathematical proofs that turn out faulty, mathfags would produce faulty software.

I'm sure mistakes would be made but you're ignoring the fact that it would lead to a major reduction of mistakes. That's like saying condoms aren't 100% effective why bother.

I really don't care if a trained computer scientist has bad programming skills or even non-existent programming skills. A trained computer scientist shouldn't have much trouble getting through a beginner's programmer course.

I do care for a trained computer scientist to have a solid theory about mathematics and more specifically, the mathematics that is computer science. I need my computer scientists to formally prove the computations of any information system that they analyze. It is merely a bonus if they can transform that computation into computer software.

I'd take sex with a small risk vs no sex any day. Mathfags produce nothing. I guess technically, that nothing is very safe.

You're in for a surprise.
k, you can take the guys who spend all their time masturbating over Haskell while producing nothing but papers that you can't view as they require journal subscriptions and I'll take people like Linus and Carmack.

linus is too dumb for haskell

Only the smartest people who never actually write any software use Haskell.

Mathfags were corrupted by government welfare to produce AIs to fight the soviets. Most lisp machines were subsidized for AI research. So many of the early "mit hackers" learned how to lie about what they could deliver for funding.

Charles H. Moore who invented forth is a borderline mathfag who has gotten shit done. Just ignore all the university bound welfare queens when looking at the situation.

I'd not say inventing forth was getting anything done. It's one of the canonical examples against extensibility, and very little was ever made with it. Kinda like lisp.

I have a feeling this actually does something terrible

This book is being used by the KGB to spread false information about the United States. My fear is that people will believe it.

That's funny, I recall Carmack praising Racket a few years back.

Linus is a trained computer scientist.

...

I seem to recall him praising Minecraft, too. But he's retired and no longer writes much of anything.

He was just a student when he wrote it. And 'trained computer scientist' professors would have given him an F.

If SICP feels heavy you can always start with HTDP, taking it has definitely made me a better programmer.

What does that have to do with anything? Linus Torvalds is a trained computer scientist. Getting an F is irrelevant to anything because Linus has a computer science degree.

I thought he was heavy into VR programming for Oculus?

He was doing some light engineering for the sensors before it was bought and re-purposed as an advertisement delivery device. I haven't heard of him doing any real work on it since. The whole project is frozen in time from the Facebook purchase - the hardware is essentially Crescent Bay from 2014.

just for the newfags in this thread, a pseudocode fix for the code in that image is
if (!this.WitnessedCorpse){ this.Subtitle.UpdateLabel("Teacher " + CleanWitnessed(this.Witnessed) + " Reaction", 1, (float)6); this.GameOverCause = CleanWitnessed(this.Witnessed);//obviously you could just set this.Witnessed = CleanWitnessed(this.Witnessed) if you didn't want to run the function everytime you need to use the variable}string CleanWitnessed(witnessed){ //function that takes this.Witnessed and cleans it down to one "word", i.e. input is "weapon and blood" and output is "weapon", on the basis that Insanity > Weapon > Blood [which is what I can tell from what's provided]) if (this.Witnessed.contains("Insanity") { return "Insanity"; } else if (this.Witnessed.contains("Weapon") { return "Weapon"; } else if (this.Witnessed.contains("Blood") { return "Blood"; } else (error)}

just realized i fucked up the parenthesis on the conditionals
(this.Witnessed.contains("yadayadayada"))
and the first part could be streamlined to
this.GameOverCause = CleanWitnessed(this.Witnessed);this.Subtitle.UpdateLabel("Teacher " + this.GameOverCause + " Reaction", 1, (float)6);

I'm not so sure about the efficiency of this solution because it still contains a conditional chain, however this time the conditionals serve the most concise/required purpose because they're used to handle the arbitrary state names for the this.Witnessed variable. However, it's a ton more efficient than having a conditional for EVERY FUCKING GODDAMN SCENARIO AND COMBINATION
so i'm fine with it

Learning C will turn you into a Ctard. You're going to think C limitations are fundamental hardware limitations, but you won't even think of them as limitations because Ctards think C is "the most powerful" language.

What are these C limitations? There are a few things I need compiler builtins for, but other than those, I can do pretty much anything but self-modifying code and I can get close with call patching like glibc does.

His code will be much faster than yours. Mono can convert his code into a hash lookup while yours has to scan the string several times due to using contains(). You're also generating garbage on that UpdateLabel() that he might not be doing, although what he does with those values isn't shown.
t. gamedev

iirc the conditional goes on for a few hundred "else if" functions, what about that?
does it do that automatically?
yeah but that's a function for displaying game over text, ideally its runnimg like once every 10 minutes, it shouldnt be running like 1000 times a second
the point is anyways its super bad form

It's no problem.
Yes. Try making a simple switch statement that compares a bunch of strings and returns a number for each, compile it with Mono, then use dnSpy or whatever to view what it generated. You'll notice it converted all the string comparisons to a Dictionary lookup at compile time. MS .NET probably does too but I'm more familiar with Mono.

Good form is meaningless if it provides bad results.

Is this book a good place to start or should I get something written this decade? I'm not a complete beginner, I've taken Java and Python classes in uni.

As a rule, it's almost always best to read a book on a language from the author. Yes, read it. Afterwards you should read the C11 standard.

Also read SICP at some point, and ignore the simpletons in this thread stating otherwise.

Any way to get a 2 bit value in java?
I need to work with variables that could only assume 4 values.
I was thinking of using enums, but apparently they are regarded as objects and objects are 8 bytes and up.
The closest I got was the byte type, which is 8 bits and still has an retarded overhead of 300%.
Two booleans could be a good idea, but it's already going into an array, so it'd turn into a two dimensional array which has an overhead the size of the observable fucking universe, plus no one knows what size the VM will give the boolean.
What is the deal with "new" languages and shitty bloated data types?

Just use booleans or numeric variables. Contains and equals are fucking functions, which should already be redflags, basic operators are always faster.
Considering there's only "weapon" and "insanity" for brevity purposes, I'd probably do something like this
short WEAPON= 0;short INSANITY= 1;boolean witnessed[] = new boolean[2];//random codeif(witnessed[WEAPON]){ if(witnessed[INSANITY]){ //insanity and weapon } else{ //weapon only } }else{ if(witnessed[INSANITY]){ //insanity only } else{ //error }}

If you need to go that low level use C. The only high level language I recall that has really good bit handling built in is Erlang.
erlang.org/doc/programming_examples/bit_syntax.html

I know, I usually do shit in C or python since I haven't learned Lua yet, but it's for uni.

2 bit variables will have more overhead than a regular int or byte. Whenever you use them they will always need to be unpacked and packed.
If you still want to use them, you implement it by packing them into a byte (any integer value data type works). Every 2 bits of the value of the variable represents one of your 2 bit variables.

That seems useful, but I guess it's not the best alternative in this case. I'll be going through an vector of hundreds of values and only accessing each value once, so the packing and unpacking would most likely slow it down a lot.
I guess I'll just stick to bytes then.
Thanks anyway, have a dank anti-turk maymay.

You can do this in Ada.
with Ada.Text_IO;use Ada.Text_IO;procedure Meme is type Data is mod 4; type Data_Array is array (Positive range ) of Data; type Unpacked_Data_Array is array (Positive range ) of Data; pragma Pack(Data_Array); A : Data_Array(1..1024); B : Unpacked_Data_Array(1..1024);begin Put_Line("A uses " & Integer'Image(A'Size) & " bits."); Put_Line("B uses " & Integer'Image(B'Size) & " bits.");end;

Output:
A uses 2048 bits.B uses 8192 bits.

It's generally a bad idea to do bit-based datastructures in Javalikes, but you can do them like in C with tightly packed integer arrays. People usually avoid using the sign bit in Java, and avoid uint in C# due to compatibility problems. Be sure you know why you're using them before you do. In the game I work on, they're used to represent various aspects of base building in a 3D grid, where players might create huge megabases of 100M grid cells so size of the data matters.

I remember the greybeard Ada types in the '90s complaining about Ada and playing the blame game for who was responsible for its decisions but it's always looked like a reasonable language to me as someone who didn't have to use it. I wonder what horrors only become apparent when trying to build large software projects with it.

Same. I looked through Ada's libraries recently (in response to another thread) and the code was such a joy to read. I suppose the complaints you recall could be down to the vocal minority having the loudest voice.

If you have 0 experience with programming, pick a language like Python or JavaScript.

Autists here are gonna reee simply because they're easier languages to learn for beginners, and heavens forbid anyone who browses Holla Forums take the easier option ever.

Once you gain a better understanding of programming you'll see the flaws those languages have and move to a more Holla Forums-approved language such as C or Rust.

LOL

Isn't it's much harder to understand what happens on the machine when you code in Python and JavaScript?

Anything that isn't assembly abstracts what's happening under the hood. And assemblers will sometimes change the code on-the-fly as well. Anything that isn't binary coding using op code tables abstracts what's happening under the hood.

Heh, that was no vocal minority. That whole industry imploded violently. Think of PHP where it looks ok from an initial glance yet everyone seems to loathe it and projects try to avoid developing with it. There's obviously something terribly wrong, but exactly what might take actually using it to understand.

You're forgetting about microcode m8.

Not really. Only thing I can think of is LEA shortening on x86 but that's a pretty big stretch to say it was changed.

It doesn't.

As you say this on a website running PHP...

Only hipsters. Everyone else knows PHP is pretty solid.

Sounds like you're at that "might take actually using it to understand" stage. You'll write some code someday, user. I believe in you.

PHP is a mess.
PHP is a big fat mistake.

Ada stopped being used because of a greater demand for programmers, and in the supply of programmers there was more familiarity with C++. On paper, it was cheaper to hire a C++ programmer instead of the Ada programmer. If we base quality on this metric, Javascript is the greatest language in existence, and we should use it for everything.

I've written a lot in PHP(5). It's solid.

PHP sucks primarily because it lacked conventions initially, so you end up with a disgusting inconsistency. Very disgraceful.
That said, Laravel is probably the best web framework I've worked with of any language. Neatens shit up and very easy to dev with.
PHP7 is also pretty fast.
Personally, for the simple reason that frontend code is written in JS, I'd like Web Frameworks to be built on Node. Parts of frontend/backend sometimes need to share same code and it's a real shit in the bush having to write it twice: once in PHP, once in JS.

If you like the front end and backend to share code, give Clojure and ClojureScript a try. It's pretty neat and not nearly as difficult as hipster bloggers make it out to be.

It's disgusting JVM shit which is only nice if you like to watch your memory ballon.

LARP

How delightfully amusing.

The fastest go-kart is still a go-kart.

There's your problem.

pro-fact: build a car with 4 wheels and a chair and as long as it doesn't go over 5 mph call it a wheelchair and you won't need a license or insurance. true story.

...

...

Even more disgusting. Tell me, how many megabytes of bloat do you bundle on the end user just so they have the privilege of running your generated garbage?

The JVM has a horrible track record for exploits. Count yourself as a moron.

Name at least one unsoundness bug in JVM found in last 4 years, for example.
Compare it to total number of bugs found in "native" applications.

I would have to wade through way too many JVM exploits to find it, can you imagine how many there have been in four years?

C/C++ has a horrible track record for exploits. Count yourself as a moron.

What would you say if I told you the JVM was C/C++ underneath! Truly, I tell you it is so.

...

then it should be easy to find one, cuckboy.

One error in your C programs only makes it bad. One error in the JVM compromises all the java programs.

The famous "PHP: a fractal of bad design" and the other anti-PHP articles are specific lists of problems with the language. I have never seen anything like that for Ada.

One error in libc compromises all the c programs.
before you say that it doesn't effect c applications using a different libc, know that there are other implementations of the jvm

Javafags eternally BTFO

Well that's almost true but:
1) An error will usually affect only one function.
2) A (Java) VM is A LOT more complicated than a libc.

That’s because executing arbitrary code from websites on your machine is dangerous even if the browser is trusted.

Exactly. Thanks for confirming that you believe the JVM is worthless too.

What part of "arbitrary code" don't you understand? The same applies to JavaScript.

They kept ecmascript. They dumped Java. Java is garbage.

javascript is worse

Untrue. Feel free to install the JDK and turn the browser shit on, though.

Going back and forth on a list of billions of values, so I decide to use LinkedList and then get the ListIterator from it
Jesus fucking Christ this shitty fucking language. Why do people use it? Poeple say it's simple, but fucking python would be better at this point if you don't care about optimization that much.

A single bit flipping in ram fully compromises a JVM because the security is based entirely around not letting you create a pointer. That makes them fundamentally and hopelessly insecure compared to C as any bad hardware or computer with insufficient cooling can be exploited with the same code. Judging by the number of even experienced builders who see their boxes crash in prime95 high heat AVX testing, that's probably most PCs.

Because businesses are run on nickels and dimes and CTO's have to listen to CFO's so they choose the cheapest, laziest language available. Avoid the meme languages. They are crippled by design.

There's a vocal group on Holla Forums who are staunch advocates of SICP and call people names when they disagree.

ergo sum SICP is shit

Underrated. There is more than one model of computation. SICP is a big picture book that helps you understand what CS is, and the archatecture and design of programs with big ideas like state, mutability, recursion, iteration, acculumation etc. Starting with the big picture may not be for everyone. After years of C programing, I found it truly enlightening.

Premature optimization. Code should be written in good form, and the compilier should optimize. Writing bad form for performance gains is a hack, that leads to trouble maintaining and possibily security bugs.

t.code artisan