r/programming • u/jonjonbee • Jun 05 '18
Code golfing challenge leads to discovery of string concatenation bug in JDK 9+ compiler
https://stackoverflow.com/questions/50683786/why-does-arrayin-i-give-different-results-in-java-8-and-java-10
2.2k
Upvotes
View all comments
Show parent comment
5
u/rebootyourbrainstem Jun 05 '18 edited Jun 05 '18
This is a very common idiom in C. It's very succinct and expressive, which is pretty hard to come by in that language.
Basically
array[i++] = expression;says "I do this to element number i and now I'm done with it, move on to the next one".In other languages there may be better ways to express this (iterators, generator expressions, list push/pop methods) and even in C it's often cleaner to do the increment as part of a for loop, but this pattern definitely has its uses.
An example: