News for hackers. Stuff that matters.
Re:Please put units in names by Closi on Monday March 21, 2022 @04:33AM (#30751670)
I used to work at a company with two database fields, speed_kmph.

The documentation read "speed_kmph - This field contains the travelling speed in MILES PER HOUR - please do not be confused by the name".

Woo, great job guys.

Re:Please put units in names by quickthrower2 on Monday March 21, 2022 @05:47AM (#30752111)
DB field names can be really hard to change. All those crystal reports to update, and the sales managers pet access DB that the hero set up for him that you don’t know about.
Re:Please put units in names by tonyedgecombe on Monday March 21, 2022 @06:08AM (#30752250)
>DB field names can be really hard to change.

I find it really hard to accept any excuse for something like that. It's why enterprise code is so sloppy, people doing the most expedient thing rather than what is correct.

Re:Please put units in names by Closi on Monday March 21, 2022 @10:59AM (#30754869)
How do you write code so that it can accommodate DB field name changes without breaking SQL reports / BI?

Might be easy if you own the whole codebase and all reporting, but you are also going to break all those linked BI reports that the analysis team has written.

Re:Please put units in names by Too on Monday March 21, 2022 @01:30PM (#30757123)
Breaking the report is a feature.

If you don’t, it will assume kmph instead of mph and just present the wrong data! But sure…those graphs still look pretty…

Re:Please put units in names by Closi on Monday March 21, 2022 @07:22PM (#30761007)
Which links back to the original point from quickthrower that database field name changes are really hard to change then.

If you can’t make a change without it potentially breaking other stuff, it goes in the “not easy” category for me. Especially if you probably won’t know if stuff is broken until the change is pushed to prod.

Re:Please put units in names by im3w1l on Monday March 21, 2022 @03:17PM (#30758475)
Create a new column speed_mph. Create a trigger that makes writes to either column gets written to both (make sure to write it to avoid infinite recursion). Copy all data from speed_kmph to speed_mph. Deprecate speed_kmph. Change existing usages at your leisure. Delete speed_kmph.
Re:Please put units in names by gilcot on Tuesday March 22, 2022 @07:56PM (#30773169)
You can't just copy data, it's said to be they're factor k (i.e. 10^3) hahaha Even switching to "speed_mph" still makes the warning/comment relevant: that just means that "m" is for "miles" and not "meters"
Re:Please put units in names by Closi on Tuesday March 22, 2022 @03:52AM (#30763618)
Fair enough, although sounds like it’s really hard to change then back to quickthrowers point.
Re:Please put units in names by pojzon on Monday March 21, 2022 @12:53PM (#30756464)
Most often those reports are built on top of table views and not direct table contents. If you have an abstraction layer between its not hard to change whats under.

But that makes an assumption you didnt make any shortcuts.

Re:Please put units in names by Closi on Monday March 21, 2022 @07:19PM (#30760982)
Considering I was actually consuming the data, if there was an abstraction layer then the field name was in that.
Re:Please put units in names by cle on Monday March 21, 2022 @10:47AM (#30754739)
What is "correct" is up for debate, and often depends on cost tradeoffs. Sometimes this is the "correct" thing to do, no matter how gross we think it is.
Re:Please put units in names by tonyedgecombe on Monday March 21, 2022 @06:28PM (#30760571)
Not often, what has always surprised me is how regularly these sort of problems are self inflicted. A lot of people will just do what is expedient regardless of what the management position is.
Re:Please put units in names by bombcar on Monday March 21, 2022 @09:55AM (#30754144)
This is why it's dangerous to encode the unit in the variable, because it will eventually change (we had code that was measured in seconds and had to be changed to measure in 20/ths of a second for more granularity, if the timer variable had been named "timer_seconds" it would have had to be changed everywhere.
Re:Please put units in names by RandallBrown on Monday March 21, 2022 @12:31PM (#30756089)
If you change the unit, I think the variable should be changed everywhere.

It's hard to know what assumptions code is making and by forcing you to change the code everywhere (which should be pretty easy in any modern IDE) you at least have a chance to evaluate any issues that unit change could cause.

Re:Please put units in names by andrewzah on Monday March 21, 2022 @01:51PM (#30757393)
Someone doing a half-assed refactor doesn't mean it's "dangerous" to encode a unit in a variable or function.

I do agree that generally it's better to use something like a struct that's more flexible, but doing that for every function is also quite verbose. For some functions the time requirement may never change as well.

Re:Please put units in names by hallway_monitor on Monday March 21, 2022 @10:13AM (#30754352)
In this specific case, it seems like creating a new property with the new data in a new name would be the safest path forward. Ensuring the unit are in both property names will prevent confusion.
Re:Please put units in names by llbeansandrice on Monday March 21, 2022 @12:37PM (#30756198)
This sounds like a feature to me and modern IDEs make this type of simple refactoring quite straight forward for most languages.
Re:Please put units in names by jrodthree24 on Monday March 21, 2022 @03:01PM (#30758271)
It's even better when the documentation gets stale too. And now this is in meters/second but the name implies km and docs specify miles.
Re:Please put units in names by gpderetta on Monday March 21, 2022 @08:06AM (#30753080)
recently I was looking at some pcap parsing code which was storing the timestamp field into a timeval structure (that nominally has usec precision), but then treating it as nanoseconds (as pcap supports both resolution). It made for some very confusing reads!