So recently at work we've been discussing the use of shorthand code and why it is good/bad.
I'm personally one for constantly searching out more efficient or syntactically pleasing ways of doing things, but this isn't being well received.
What's the general opinion here? Is readability of code absolutely paramount for everyone who might look at it? Or can you assume a certain level of understanding when it comes to shortcuts?
I'll use JavaScript as an example so that input can come from more people but really this relates to any programming language, in my case JavaScript and C#.Net.
One example is using the below, where the + character is shorthand for the parseInt function:
I understand that this might look confusing to people who don't know that syntax, but surely the same can be said for all programming languages? For example we use the following absolutely everywhere and I think it would be just as confusing for a new developer to understand.
What do you guys think? Is it wrong to use things like this or should I argue my corner a little more?
It may be worth noting that this is part of an application worked on by a small (< 5 persons) development team.
I'm personally one for constantly searching out more efficient or syntactically pleasing ways of doing things, but this isn't being well received.
What's the general opinion here? Is readability of code absolutely paramount for everyone who might look at it? Or can you assume a certain level of understanding when it comes to shortcuts?
I'll use JavaScript as an example so that input can come from more people but really this relates to any programming language, in my case JavaScript and C#.Net.
One example is using the below, where the + character is shorthand for the parseInt function:
Code:
var s = "0", i = 0;
if (s===i) {
alert("match");
} else if (+s===i) {
alert("parsed match");
}
I understand that this might look confusing to people who don't know that syntax, but surely the same can be said for all programming languages? For example we use the following absolutely everywhere and I think it would be just as confusing for a new developer to understand.
Code:
var b = false, s="";
var s = (b) ? "true" : "false";
What do you guys think? Is it wrong to use things like this or should I argue my corner a little more?
It may be worth noting that this is part of an application worked on by a small (< 5 persons) development team.