Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@Alice there are 2 lines in between but i isnt changed or accessed in any way. I guess it once had a non zero value and somebody forgot to remove it.
-
Wack63117y@vadimir but my "Computer Architecture and Systems Programming" teacher allways tells us that the compiler is our friend!
@irene why not? It's a pretty quick fix, so that should be optimizable, hell a c++ compiler even replaces a recursive call to a function calculating fibonacci, if it detects that it's called by a constant, with just the result. So those should be fixable too... -
Wack63117y@irene so let's say you have a funtion to calculate fibonacci something like
function int calculate(n){
if (n < 2) {return 1;}
return calculate(n-1)+calculate(n-2);
}
And it's somewhere called with something like
int n = 2*3;
int result = calculate(n);
A compiler will know n is static, and won't change, so first it replaces that line with
int n = 6;
It will also replace the line with the result woth simply
int result = 13;
As it will follow recursive functions up to some point if it sees a static input to them. Compilers are smart. Compilers are your friend. -
donuts238487yDoes reading The source of OSS actually make you a better coder? I remember I read a few years ago the code for Hadoop but all I see is lots of interfaces and methods calling other methods which eventually comes down to methods that contain a few lines of code and not clear what exactly it's doing and why it's a method that seems to just swap some variables...
-
@billgates that's a pretty interesting question!
I've seen a ton of open source projects with really bad (code) quality, so I can only hope that nobody considers them a "role model".
The more abstract code you mentioned has _probably_ higher code quality, but one has to really dive into the source code to understand how things work. Disclaimer: Code with abstractions and interfaces can be really really bad, too ;)
You can't have it both ways I guess...
Related Rants
While reading through the Elasticsearch (Java search engine) source code a while ago I found this gem:
return i == -1? -1: i;
I think someone should stop drinking while coding.
Some other nice lines:
int i = 0;
return j + 1000 * i;
Are these guys high?
undefined
spanish inquisition
clean code