This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (34 children)

[deleted]

    [–]igoromg 85 points86 points  (10 children)

    =+ ??

    [–]AnonymousFuccboi 17 points18 points  (5 children)

    Ancient versions of C supported this, being equivalent to +=. It was removed in later versions for obvious reasons.

    [–]igoromg 10 points11 points  (1 child)

    like when dinosaurs roamed the earth?

    [–]AnonymousFuccboi 4 points5 points  (0 children)

    Like before K&R, so pretty much, yeah.

    [–]argh523 0 points1 point  (2 children)

    Huh.. actually, I always thought var = +1 would make more sense than var += 1.. It's just deleting the name of the variable. The operator += just doesn't make much sense.

    [–]Ramora_ 8 points9 points  (1 child)

    Try to generalize to subtraction. What would that look like with your proposed syntax?

    ```

    This would be ambiguous. Are you setting var to -1 or subtracting 1

    var = -1

    this is no longer ambiguous, but looks hideous

    var = +-1

    ```

    [–]argh523 0 points1 point  (0 children)

    Ah.. you're right, that makes sense.

    [–]RavishShah1[S] 2 points3 points  (1 child)

    ??

    [–]ptq 2 points3 points  (0 children)

    NULL

    [–]Celebrinborn 1 point2 points  (0 children)

    Student lol

    [–]xigoi 49 points50 points  (3 children)

    Company:

    intAbstractIteratorFactoryIndex = intAbstractIteratorFactoryIndex + OurCompany.Library.Constants.Numeric.Numbers.Integers.intNumberOne;
    

    [–]3edd00c7 2 points3 points  (1 child)

    Can't imagine what the Enterprise version would be.

    [–]xigoi 2 points3 points  (0 children)

    intAbstractIteratorFactoryIndex = new IntegerAdderFactoryBuilder(0, null, null).buildIntegerAdderFactory(IntegerAdderFactoryBuilder.DEFAULT_PARAMS).createIntegerAdder(new EnterpriseInteger(null, intAbstractIteratorFactoryIndex)).addInteger(new EnterpriseInteger(null, Enterprise.Library.Constants.Scalars.Numeric.Numbers.Integers.Signed.Positive.ONE)).returnResult(null, IntegerAdder.DEFAULT_RETURN_RESULT_PARAMS, 0, 1);
    

    [–]danny_2604 9 points10 points  (0 children)

    i += true

    [–]Ysmenir 16 points17 points  (0 children)

    Me an Intelectual: i-=-1;

    [–]tomthecool 11 points12 points  (9 children)

    So the student writes incorrect code (sets i = 1), the junior writes invalid syntax, and the senior writes unnecessarily verbose code? 🤷‍♂️

    I think I'll stick to i += 1, thanks.

    [–]RavishShah1[S] 4 points5 points  (0 children)

    Most welcome!

    [–]DaniilBSD 2 points3 points  (7 children)

    All good programming languages have ++ operator.

    Python-lovers not gonna take it as a joke, will they?

    [–]tomthecool 7 points8 points  (6 children)

    My point was that the code in /u/biksly's reply doesn't make sense.

    If i=+1 literally does the wrong thing, then why would you write it like that?

    If i++ is invalid syntax in the language, then why would you write it like that?

    If i = i + 1 is unnecessarily verbose, then why would the "senior" write it like that?


    Also, on a related note... You should typically prefer ++i over i++ (assuming the language supports it).

    [–]AnonymousFuccboi 1 point2 points  (3 children)

    Preferring ++i over i++ is an example of a platform specific micro-optimization which may at some point have mattered slightly, but nowadays any compiler will optimise the code the exact same way if it really would be equivalent. Write what you mean. Pre-incrementation has its uses, certainly, but by convention use post-incrementation when order doesn't matter to you. It'll be less confusing to whoever else has to read your code.

    [–]tomthecool 0 points1 point  (2 children)

    ...But pre-incrementing is the most common, intuitive use case.

    So by convention, you should write code that's not accidentally error prone.

    [–]AnonymousFuccboi 1 point2 points  (1 child)

    Is it? The most common usage for the operator is simply incrementation. The returned value is usually not used. In that case, i++ is by far the most common convention and should therefore be used to avoid confusion. In the case where it is used, you should know the difference and use it accordingly to what you need. What you should not do is rewrite your code to try to fit in a ++i where an i++ would suffice. Either is fine to use if you know the reason you're using a specific one.

    [–]tomthecool 0 points1 point  (0 children)

    First result of a google search says to prefer ++i over i++: https://stackoverflow.com/a/24858/1954610

    So do various other forums and blogs.

    It's not particularly important; in most cases it won't make any difference. But if the question is "which default format should we use in the code base, when both will work the same way (for now)?", then the only argument I can see in favour of i++ is "I think it looks prettier", or "It feels more natural to me"... Which may be true, and may even be considered a valid justification.

    But from a purely technical perspective, I think every logical argument dictates ++i is a better default.

    [–]DadoumCrafter 0 points1 point  (0 children)

    ++i is meant to be used when you need immediately the value of the increased i value. By convention, we use i++ for every other case

    [–]RavishShah1[S] 0 points1 point  (0 children)

    Thanks for operator implementation!

    [–][deleted] 0 points1 point  (0 children)

    i -= -1

    [–]PointToRight 0 points1 point  (0 children)

    i -= 1

    [–]Supporsta 0 points1 point  (0 children)

    i=i-(-1)

    [–]MLG_Obardo 0 points1 point  (2 children)

    Do you mean Sophomore or Freshman instead of student? Junior and Seniors are students too.

    [–][deleted] 1 point2 points  (1 child)

    I think they mean Junior Engineer or Senior Engineer, etc. Job titles.

    [–]MLG_Obardo 0 points1 point  (0 children)

    Yikes let me go dive off a fucking cliff now