Programming thread

is it actually beneficial to optimize your code before compile or not? i know that it depends on the code itself but im talking about in general.
No.

But you are right that compilers can't catch everything. But the best way to do it is to profile the program while running to see what the compiler missed (or couldn't do). Anything else and you'll likely be wasting time for meager performance gains.
 
i have a genuine question for you dev boys.
i remember talking to some senior dev troon on discord and he said that you dont need to optimize much as the compiler does it for you.
now i know compilers do apply some optimizations but i also know that they arent a catch all and that some shit doesn't get optimized.

the troon argued with me saying my views were outdated and i ended up ignoring him but it does still linger on my mind.

is it actually beneficial to optimize your code before compile or not? i know that it depends on the code itself but im talking about in general.
Compilers optimize code as-written. If your code is stupid and slow due to logic the compiler isn't going to help. If you decided to busy wait instead of using callbacks or whatever, the compiler won't fix that. If you use 64 bit data-types and waste 4x the RAM and you're using a lot of them, the compiler won't optimize that.

What it will do is the simple stuff, unrolling loops, branch prediction, operation ordering, etc. So, you don't need to necessarily scrutinize every line and think "maybe there's a faster way". Until you profile it and realize the compiler didn't help enough.
 
i have a genuine question for you dev boys.
i remember talking to some senior dev troon on discord and he said that you dont need to optimize much as the compiler does it for you.
now i know compilers do apply some optimizations but i also know that they arent a catch all and that some shit doesn't get optimized.

the troon argued with me saying my views were outdated and i ended up ignoring him but it does still linger on my mind.

is it actually beneficial to optimize your code before compile or not? i know that it depends on the code itself but im talking about in general.
I take the attitude that clear code is preferable to less clear, hand optimized code. If you aren't getting sufficient performance, benchmark the code to find trouble spots and optimize those.

Also different languages offer more or less opportunities for a clever compiler to optimize things. In particular, more functional languages can do things like reuse portions of data structures.

I'm a fan of Ocaml. It's mostly a functional language but unlike Haskell it isn't purely functional. It does provide side effecting operations but 90% of your code will be purely functional. You do have the escape hatch of the side effects when you need them.

Basically what @Markass the Worst and @davids877 said.
 
i have a genuine question for you dev boys.
i remember talking to some senior dev troon on discord and he said that you dont need to optimize much as the compiler does it for you.
now i know compilers do apply some optimizations but i also know that they arent a catch all and that some shit doesn't get optimized.

the troon argued with me saying my views were outdated and i ended up ignoring him but it does still linger on my mind.

is it actually beneficial to optimize your code before compile or not? i know that it depends on the code itself but im talking about in general.
Another thing that hasn't been mentioned yet is that performance profiles have changed massively over time. In the old days, computers were slow and every instruction counted, so it was worth microoptimizing every little thing. Nowadays, computers are much faster but process larger amounts of data; as a result, most of the time is spent in that very small code section that goes over your large input. If the thing you're optimizing makes up 10% of the total runtime, the most you can achieve is an 11% speedup. I recently worked on something that spent 80% and 18% of its time on two functions respectively, so there was no reason to optimize anything unrelated to these two. If you don't measure what tiny part of your code is actually performance-critical, chances are that you will waste your time, both optimizing it and dealing with the less readable optimized version later.
 
Most terrible performance these days is caused by programmers that write terribly backwards logic because they don't understand simple programming principles or how a computer really approaches things when it comes to their program. As has been said, there's no compiler on earth that can fix that. That's why I'm always a bit critical of the "the compiler will handle it" line. Its kinda true but at the same time I think it's not a good thing to teach. While it's true that those micro optimizations are usually a waste of time and can make things more complicated, I feel there'd be a lot less shit software if newcomers would learn to do them because it'd make them think more about how a program is put together, so to speak. For a current very publicized (and funny) example, look at the mess City Skylines 2 is. That wouldn't have happened if the programmers responsible were thought to think about such details instead of only thinking in high level abstractions. (and obviously not understanding how they come together on a lower level)

I am from times though when optimizing code (even what the compiler spit out in assembler) was downright necessary, and "excessive cleverness" of programmers also often was a source of bugs then. So it's complicated.
 
Most terrible performance these days is caused by programmers that write terribly backwards logic because they don't understand simple programming principles or how a computer really approaches things when it comes to their program.
I was looking at a program that processes some data and displays it. I wanted to make it use a different data source where it would use 4x the amount of data, I figured maybe 4x slower, shouldn't be too bad. Made the changes... it was SLLLOOOOOWWWWWWWWWW.

Turns out they had managed to implement not O(n) not O(n^2) but O(n^3), look up O() if you haven't seen it.
They were basically doing:
Code:
for i in data_to_display[]:
    for j in data_to_display[]:
        for k in data_to_display[]:

Which means it wasn't 4x slower, it was 64x slower.
Instead of investigating further, I backed away slowly and switched to some code not written by absolute morons.
 
A JS tutorial im watching is teaching MVC architecure with base javascript. Should I learn MVC or should I jump straight into react?
 
I was looking at a program that processes some data and displays it. I wanted to make it use a different data source where it would use 4x the amount of data, I figured maybe 4x slower, shouldn't be too bad. Made the changes... it was SLLLOOOOOWWWWWWWWWW.

Turns out they had managed to implement not O(n) not O(n^2) but O(n^3), look up O() if you haven't seen it.
They were basically doing:
Code:
for i in data_to_display[]:
    for j in data_to_display[]:
        for k in data_to_display[]:

Which means it wasn't 4x slower, it was 64x slower.
Instead of investigating further, I backed away slowly and switched to some code not written by absolute morons.
The extra computing time is neccessary for doing the needful.

E: coming back to this, no way you can just drop a bomb like that and not post a link
 
Last edited:
A JS tutorial im watching is teaching MVC architecure with base javascript. Should I learn MVC or should I jump straight into react?
Understanding the theory behind MVC is a good idea, but the higher level idea of splitting your code into different concerns is even more important, and essential to becoming a good programmer. However, React doesn't follow the MVC pattern (without you forcing it to), so it won't help you code React directly.

So, definitely do put some time into learning MVC, but your primary practical focus should be on becoming conversant with React and it's own ways of managing view state.
 
is it actually beneficial to optimize your code before compile or not? i know that it depends on the code itself but im talking about in general.

No, and in addition, it is generally a waste of time to optimize without relying on a profiler.

Most terrible performance these days is caused by programmers that write terribly backwards logic because they don't understand simple programming principles or how a computer really approaches things when it comes to their program.

I would say most terrible performance is caused by nigger-rigged data structures. I know of a guy who is unironically considered a genius for spending about a year replacing linked-lists with arrays. The kicker is that the linked-lists were used to represent matrices. He got 10x-50x speedup in a range of use cases, and anyway, he got promoted to head of the division and fired everyone who knows his secret.
 
No, and in addition, it is generally a waste of time to optimize without relying on a profiler.
You don't even need a profiler, even a couple of print statements for elapsed time in suspected hot spots will do in a pinch. Still good to do function level profiling, because it's less work overall and can also catch hidden performance errors.
I would say most terrible performance is caused by nigger-rigged data structures. I know of a guy who is unironically considered a genius for spending about a year replacing linked-lists with arrays.
Algorithmic complexity and cache-friendliness are two things that are all but lost on modern pajeet devs.
linked-lists were used to represent matrices
:story:
He got 10x-50x speedup in a range of use cases, and anyway, he got promoted to head of the division and fired everyone who knows his secret.
This is one of those things that compilers can't fix. Yes, the compiler stops you from having to worry about the instruction pipeline or which way your for loops go (down is slightly faster on common architectures for executing a block of code n times), but it can't stop absolute retards from using linked lists for matrices and slowing things down by several orders of magnitude because of all the dereferences.
 
If it was sorted data I would hope they also dispersed some skip links throughout as well, for faster searches.
Obviously the correct solution is to link each element to every element, including itself. Can't have a good matrix implementation without being able to index every value! Man, if only there was a way to compactly store a rectangular array of numbers... I know! Let's store all our links in a linked list!
 
Obviously the correct solution is to link each element to every element, including itself. Can't have a good matrix implementation without being able to index every value! Man, if only there was a way to compactly store a rectangular array of numbers... I know! Let's store all our links in a linked list!
I believe this is called the "Alabama Tree" where there are always loops in the family tree and everyone is related.
 
I was looking at a program that processes some data and displays it. I wanted to make it use a different data source where it would use 4x the amount of data, I figured maybe 4x slower, shouldn't be too bad. Made the changes... it was SLLLOOOOOWWWWWWWWWW.

Turns out they had managed to implement not O(n) not O(n^2) but O(n^3), look up O() if you haven't seen it.
They were basically doing:
Code:
for i in data_to_display[]:
    for j in data_to_display[]:
        for k in data_to_display[]:

Which means it wasn't 4x slower, it was 64x slower.
Instead of investigating further, I backed away slowly and switched to some code not written by absolute morons.
I get the sense this is the sort of thing the root of the problem is. Mastering time complexity is rapidly becoming a lost art; the compiler can't save you if you're just a retard with a basic grasp of loops. Some of my buddies were complaining recently about the slow dogshit their students today write compared to just a few years ago. Beginner programmers never test their things at scale.

The kicker is that the linked-lists were used to represent matrices.
:lossmanjack:
This hurts me to my core. Part of a thesis I did involved doing heavily optimized GPU linalg. If I did this shit, I never would have completed the main task in the next decade.
 
Back