it just makes it much easier to read and less buggy. i learned this after being turned down in an interview where one of the things i did wrong was use ? : to set a variable
they broke my code down and tore me a new one. still too afraid to finish reading their assessment.
Its not unreadable but the less time i have to spend trying to figure what what the line will do the better
I want to say, keep it at one idea at a time, if that makes sense
I want to read from the top down as easily as possible. Think about when you have a file with maybe hundreds or even thousands of lines. You want to read it as easily as you read english
one line solutions are awesome if you’re the only one that has to look at it but chances are that in a professional environment lots of other people will have to look at your code. you also want people to be able to help you fix your bugs and vice versa.
at the end of the day coding is a team sport. that’s why languages are standardized in the first place. so that many people can look at the same code and know exactly what it does. so you need to always think about things you can do to make your code easy to read for the people who will come after you.
lots of companies have their own rules about how they want code to be written. so its good to learn about the “good” and “bad” ways and try to follow best practices
my interview experience has been pretty rough so far. I need to start cranking out projects more often so that I can show people what I’ve been working on. I think people who hire don’t really care about your code. They wan’t to see something you build that they can use and see working and in motion.
When you start aiming for a complete project then the learning really takes care of itself. It’s kind of an annoying cliche when people say you should just start building stuff but it’s really true. Build until you get hired then build some more.
Can’t believe I forgot one of the most simple yet important things about coding.
And yes, it’s true. I’ve watched plenty of videos advising and been in plenty of interviews where the question of “So you have projects to showcase?” has been asked.
In the end, code is code. Eyes are set on the project. Nobody will be impressed for the list of technologies you know if you don’t have any projects to confirm your knowledge.
One of my plans is to turn my GitHub io page into a showcase page.
Whatever immediate gratification you get from writing cryptically fancy or clever code is nothing compared to the headache 6 months from now when you or somebody else have to read the code.
Simple, legible code is way more valuable then clever code which places an unnecessary cognitive load on the reader. I’m not saying you can’t write clever code, just don’t sacrifice readability for it. At least not if the code is written for more then just an endorphin rush. Just my two cents.
I wouldn’t say that ternary operator is cryptic, fancy, “clever”, advanced or whatever, it’s just a matter of exposure - just like getting used to arrow functions, map/filter/reduce etc. For example when writing React using ternary is very common pattern for conditional rendering.
Just don’t write nested ternaries
BTW, here’s a function that checks if a letter is uppercase and returns true or false:
const fn = ch => ch < {};
This is what I would call cryptic, fancy, “clever”, advanced.
I wasn’t talking about the ternary I just meant code in general. That is, writing code to satisfy some ego desirer as opposed to writing code that has value for everyone.