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
-
slar3008yFreeBSD, vim, < , indentation doesn't matter as long as it's consistent (i.e. use something like astyle)
There argument settled. Anyone who disagrees is wrong. -
i = 0;
(Code)
i = 1;
(Code)
i = 2;
(Code)
i = 3;
(Code)
i = 4;
(Code)
i = 5;
(Code)
i = 6;
(Code)
i = 7;
(Code)
i = 8;
(Code)
i = 9;
(Code) -
Synti9988yvoid count(int i, int max){
if(i==max){
profit();
return;
}
//Do some magic
magic(i);
//End magic
count(i + 1, max);
} -
Salmakis6738yIf its hardcoded number then ofc <, if its stuff like maxIndex or smth then it may be n <= 10
-
Hel8y3378yDepends on the context, or more specific, depends on what makes more sense if you would translate it to plain English. If the requirements say up to and including x, then <= x, if the requirements say up to x, then < x.
-
for(var i=array.length-1; i>=0; i--) {
// optimized for performance.
// only checks length once
} -
elazar10308yAre you guys kidding me? <= and < will result in precisely the same test, if your compiler is only semi-decent.
It is important to use < for readability, since you can write exactly the same expression as for the length of the array, without arithmetic. And also simply because this is the universally idiomatic way. -
matanl26448y
-
@matanl oh. I dont know much about assembly. What's the thing they're translated to and why is it the same?
-
elazar10308y@YousifMansour
blt: branch if less than
ble: branch if less than or equal
But the compiler can generate whatever it likes, as long as the behavior is the same, so you can't know for sure what will the machine code be. -
For(int i = 0; i != rand(); i++)
# code
# pray you get a 10
Just realized my keyboard doesn't have a less than sign after the update.... Wtf -
@elazar ok shouldn't the second one take more time? Because it might need check for both conditions? Im still a student and haven't taken the computer hardware course.
-
elazar10308y@YousifMansour it's not two conditions, it only sounds this way in English. You can say that <= is "< or =" but it is equally valid to say that < is "<= and not =". It's a matter of definition, and neither is difficult for hardware.
-
matanl26448y@elazar @YousifMansour for example, if hardware implements a<b by executing a-b and checking whether the result is negative (MSB is one) then it will take 1 operation, but checking whether the result is non-positive (MSB is one or answer is zero) will take 2 operations
-
@dzil123 i mean... on one side yes, for python, but on the other side no... just no...
After Windows/Linux and atom/sublime and vim/emacs and all those other reasons we fight...
for(i = 0 ; i < 10 ; i++)
or
for(i =0 ; i <= 9 ; i++)
for 10 iterations?
undefined