When had the idea of doing multiple things on one line, i was thinking just simple stuff like assigning variables. It could just save space and have readability.
Again, you have several people telling you it is less visible. And the “space” you are saving is mainly on your editor screen - not in the finished product.
I also like compacting things because it looks professional and its better to look at.
Well, you have couple of professionals here saying the opposite. It may look cooler in an egghead-kind of way. It’s kind of cool know that it can be done. But why would you want to? I disagree with every reason you give. I would hate to have to work on that code.
“Your scientists were so preoccupied with whether they could, they didn’t stop to think if they should.” - Dr. Ian Malcolm, Jurassic Park
Compact code is better for writing comments, as you can basically explain more in a smaller space.
Your comment just tells what it does. That doesn’t tell how it does it. I know the refrigerator makes things cold. That doesn’t tell me how to fix it if something goes wrong. Your comment is just a label - a well named function could do as much. It doesn’t explain anything. To explain it properly would take 15 lines of comments. Or you could just write it out in a way that is much more obvious.
When stuff is compact, its less confusing.
Again, strongly disagree.
When code gets big, it gets confusing to see.
Then you need to break things up into functions and learn to compartmentalize.
Would you rather write 10 if statements or 10 simple 1 line conditionals.
That depends. That would be like saying, “Which is better: a screwdriver or a hammer?” That really depends.
If the ternary operations are clear, then that is what you need. Personally I don’t like your statement:
/^[aeiou]$/.test(str) === true ? str.push('way') : /^[zbtg]$/.test(str) === true ? str.push(str + str + 'ay' (str = null), (str = null)) : str.push(str + 'ay', (str = null));
I don’t think the innards of a ternary operation should have side-effects. I think they should only be used in assignment statements, returning simple expressions. If it takes me longer than two seconds to figure out what is going on, it shouldn’t be a ternary operator. If you get a job and you write code like that, every other developer is going to pitch in to hire a hitman. At the very least you need to get AAA because every day you are going to come out to find your tires slashed. You will be the most hated person there. I can’t even imagine having to debug or modify pages of code like that. And to be honest, the first time you have to go back after a year and modify pages of that code, you are going to want to take out a hit on yourself.
if statements you needed were so odious to your sight, you could have wrapped them up in a nice little function.
As one of my old programming teachers used to say, “Just because it’s true doesn’t mean that it is useful.” Yes, it is possible to code that way. I guess, to you it looks cool.