[go: up one dir, main page]

DEV Community

Jules
Jules

Posted on

Type-Safety, it's pretty nice

Okay, short one.
I'm used to programming in Ruby where anything goes and you fix stuff later. The ultimate procrastination.

That said, it's surprising how useful I'm finding strongly-typed methods and variables; it's like having comments everywhere saying what my program's doing and makes me think about design more. When I can see that this method returns a string, but the one it calls is boolean-y, I'm encouraged to consider how they interact more.

Even if it doesn't change what I do now, it saves a lot of time when refactoring, and the tests don't even have to run for me to find out that square pegs don't go in round holes.

Long and short, restrictions keep things structured, and Java's working out well (enough).

Done.

Top comments (1)

Collapse
 
xanderyzwich profile image
Corey McCarty

There are tricks for playing boolean-y stuff in reserved values. Like you can return "-". It would actually help more to return a string and for that negative case throw an exception and handle it explicitly on the calling code.