Maybe it is the way we learnt programming by patterns – “Do this and that will happen” or “this is how it is done”. Maybe we don’t stop to think how things work at more fundamental level.
Here is a piece of code which works in some languages (C, C++, JavaScript) but won’t work in others (Java, C#)
C/C++ allows a statement like 1, 2, 3;
/*
Works in C/C++
*/
int main()
{
1, 2, 3; // Why does this work? What does it mean?
}
Java and C# don't allow 1, 2, 3
/*
Java (and C#) don't allow
*/
class MyClass {
static void main(String[] args) {
1, 2, 3; // Gives an error.. Why?
}
Why do you think this is? Is there a fundamental reason these languages differ? Why did Java disallow this? If you know why, write it in comments below