One of the most salient features of our Tech Hiring culture is that there is so much bullshit. Everyone knows this. Each of us contributes his share. But we tend to take the situation for granted.
Language specific, but in Kotlin the when expression is a massive improvment over if/else
valmessage=when(x){in1..10->"x is in the range"invalidNumbers->"x is valid"!in10..20->"x is outside the range"else->"none of the above"}println("validate($x): $message")
Backend developer with +4 years of experience, continuously looking for learning new concepts and always looking for new challenges, trying to spread the knowledge I gain
One of the most salient features of our Tech Hiring culture is that there is so much bullshit. Everyone knows this. Each of us contributes his share. But we tend to take the situation for granted.
I wonder what other languages have a similarly good structure.
Not like switch case which don't return anything, something better.
Probably functional languages in general?
One of the most salient features of our Tech Hiring culture is that there is so much bullshit. Everyone knows this. Each of us contributes his share. But we tend to take the situation for granted.
Just a heads up that the Markdown we use here supports syntax highlighting, and is generally more accessible than inserting an image of code. Images of text are an issue for people using screen readers, for example, and their content won't get picked up by the site's search facility.
You can add code blocks with 3 backticks: More details in our editor guide!
Backend developer with +4 years of experience, continuously looking for learning new concepts and always looking for new challenges, trying to spread the knowledge I gain
I would say be aware of polymorphism. It's not wrong, but not the only concept.
The principle composition over inheritance is often a better choice, because you don't couple classes with an inheritance structure.
Sometimes it's a great mix to use inheritance for the structure and composition for the logic.
Backend developer with +4 years of experience, continuously looking for learning new concepts and always looking for new challenges, trying to spread the knowledge I gain
Always sharing, always learning.
I am a software engineer, who values a good work-life balance and working with a great team making an impact product over technology.
Just to add something, there is another possible iteration when you have a set of fixed conditions (like the switch), for large number of options a map is a better and more readable approach.
I am SOOOO HAPPY to see your article. For once it's "how to do it better" and not "omigosh, you should NEVER nest if-s, here's why". Glad to see people who don't clickbait.
Backend developer with +4 years of experience, continuously looking for learning new concepts and always looking for new challenges, trying to spread the knowledge I gain
Backend developer with +4 years of experience, continuously looking for learning new concepts and always looking for new challenges, trying to spread the knowledge I gain
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
Backend developer with +4 years of experience, continuously looking for learning new concepts and always looking for new challenges, trying to spread the knowledge I gain
Agree with all your points.
Language specific, but in Kotlin the
whenexpression is a massive improvment over if/elseYes, good tip but i don't use Kotlin that much, it's language specific but the idea is to make code more readable.
I wonder what other languages have a similarly good structure.
Not like switch case which don't return anything, something better.
Probably functional languages in general?
Like switch expressions for Java v12 have a look
indeed yes, I didn't know they can return a value
Rust has a nice match statement too, even though it is not functional.
I believe it is something that most functional language have and newer languages are starting to adopt it.
Just a heads up that the Markdown we use here supports syntax highlighting, and is generally more accessible than inserting an image of code. Images of text are an issue for people using screen readers, for example, and their content won't get picked up by the site's search facility.
You can add code blocks with 3 backticks:
More details in our editor guide!
Thanks! , great idea
I would say be aware of polymorphism. It's not wrong, but not the only concept.
The principle composition over inheritance is often a better choice, because you don't couple classes with an inheritance structure.
Sometimes it's a great mix to use inheritance for the structure and composition for the logic.
i.e. prefer interface inheritance (
implements; for polymorphism) over implementation inheritance (extends).The original quote (GoF, 1994, p.20):
talks about implementation inheritance.
Actually, we talked about this principle here Composition vs Inheritance, take a look π
Good post.
Just to add something, there is another possible iteration when you have a set of fixed conditions (like the
switch), for large number of options a map is a better and more readable approach.I am SOOOO HAPPY to see your article. For once it's "how to do it better" and not "omigosh, you should NEVER nest if-s, here's why". Glad to see people who don't clickbait.
Your comment made me happy also π,
You can follow me for more amazing content, and stay tuned π
Such humility too, hahahaha! π
πππ
Great read π―
nice
amazing post !
This is a good tip
In the Fail early, the final result of your change is not the same.
Because it should fail at a negative price or a discount equal or higher than 50.
Yeah, but it just example that helps illustrate the idea not more