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
-
naren1108yIn Java too, as like above comments, shorter the code, the better.
But I prefer readable code:
sum = sum + 1; -
@naren that's readable code, a good programmer will write like that and try using some good editors they show errors if u use c =c +d. I use php storm for my php coding
-
zshh38488yIt's preference. I think the code is more readable your way but I always use ++ anyway.
-
Zulukas188yAfter starting my job working in Delphi (object pascal), I never realized how much I miss "operator assign" operators.
-
It's splitting hairs, really, but that's what we do! I use += (or .= in PHP!) although it's just a preference. Shorter code would be the goal, but not at the expense of readability or maintainability.
-
The compiler should optimize both ways. It comes down to preference and readability. Some devs prefer short, dense code. That's fine for small teams that will be doing the maintenance for the life of the project. On larger teams, especially those that are distributed or contain a variety of skill levels, you're going to want to make sure the code conforms to the project's style guidelines. These guidelines will help the code seem much more uniform over the various modules, and will likely result in code that is a little verbose and easier to read for devs that are fresh on the ptoject. This will help the new guys as they are hired, and will help any future devs that inherit maintenance and new development.
-
manFrame9478yIt depends on the language. I cannot speak for all but I will say from a .Net C# perspective... ++ or += is fine for integer based additions and is technically better for efficiency. However, the worst thing you can do for efficiency is to do that with strings. When you use that for string concatenation you will create three strings in memory for each iteration in the stack thus being increasingly inefficient.
-
@simeg Not sure. I remember reading it a while back in the ol' days of PHP. Pretty sure ++$var is faster than $var++ too 😕
C++ rant, but I'm sure it is similar in other languages.
I cannot stand +=,-=; I understand it is shorter, but for some reason I would prefer seeing: sum = sum + 1; or the like. Am I just too much of a newb to appreciate it, or is it just preference.
undefined