this post was submitted on 19 Jun 2023
87 points (100.0% liked)
Programming
423 readers
8 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Those are just types. You shouldn't write types in the names. It's called Hungarian Notation, but it's just redundant. If you need to check the type of a variable, hover over it and your IDE should tell you that
temperatureThreshold
is typeDegreesCelsius
. No need to add extra cruft. There's also a question of how specific everything needs to be.It's also especially problematic if you later refactor things. If you change units, then you have to rename every variable.
Plus, variables shouldn't really be tied to a specific unit. If you need to display in Fahrenheit, you ideally just pass
temperatureThreshold
and it converts types as needed. ATemperature
type that that hasdegreesF()
anddegreesC()
functions is even cleaner. Units should just be private to the type's struct.I absolutely agree. But:
Obviously as a Hungarian I have a soft spot for Hungarian notation :) But in these cases I think it's warranted.
There are plenty of times where the type is just something generic like an integer and making a wrapper type is not worth the effort and this is a useful approach.