Hey, fellow software developers! Sometimes code passes your code bad data. Do you throw exceptions? Return false? Hope for the best? (YOLO)
Would love to hear your reasons why. And please share so other developers can weigh in.
#Developers #Software #SoftwareDevelopers #OpenSource #DivideByZeroAndConquer #Perl #Ruby #Python #Java #CSharp #NodeJS
- Exceptions (71%, 81 votes)
- Return values (23%, 27 votes)
- YOLO (5%, 6 votes)
This entry was edited (3 months ago)
Ianhopkinson
in reply to Curtis "Ovid" Poe (he/him) • • •it depends, I'm a data scientist so my code gets sent a lot of "bad" data. Sometimes it is a sign of improperly configured read mechanism (character encoding, CSV dialect are favourites). Sometimes your source does not fulfil your expectations (supplies a None when you expected an int) - this might happen millions of rows into a data source. In these cases I'd handle the issue.
#datascientist
Curtis "Ovid" Poe (he/him)
in reply to Ianhopkinson • • •@ianhopkinson Still remember building an ETL system where five pharmaceutical companies signed contracts with us, all agreeing to a stringent data format for what they were sending us.
Not one of them kept that agreement.
Ianhopkinson
in reply to Curtis "Ovid" Poe (he/him) • • •Lars Hanisch
in reply to Curtis "Ovid" Poe (he/him) • • •Elliot Shank
in reply to Curtis "Ovid" Poe (he/him) • • •Curtis "Ovid" Poe (he/him)
in reply to Elliot Shank • • •abcderian
in reply to Curtis "Ovid" Poe (he/him) • • •Tim Kellogg
in reply to Curtis "Ovid" Poe (he/him) • • •i voted “exceptions”, because i favor the let it crash philosophy, but ill do values if it makes sense, but only if it makes sense
i get eternally annoyed by code that “handles” exceptions because “that’s what good code does”, without actually adding any value, and in a lot of cases hiding problems making it impossible to troubleshoot
Allan Svelmøe Hansen
in reply to Curtis "Ovid" Poe (he/him) • • •I mostly opt to use return values and keep exceptions for "exceptional" situations and internally.
However like so many other things in this industry it depends on the specific situation, such as data source, data format, what it's used for and is it internal or externally provided etc.
William Pietri
in reply to Curtis "Ovid" Poe (he/him) • • •Greg Woods
in reply to Curtis "Ovid" Poe (he/him) • • •If the bad data is coming from outside my control and it’s not something I necessarily anticipated then I would prefer an exception thrown and aggregated somewhere for better visibility.
If that specific case keeps happening often enough as to no longer be considered surprising, I may eventually codify it and make a special return value for it.
Cristina 🏳️🌈🇵🇹🇪🇺
in reply to Curtis "Ovid" Poe (he/him) • • •MaxiTB
in reply to Curtis "Ovid" Poe (he/him) • • •blaue_Fledermaus
in reply to Curtis "Ovid" Poe (he/him) • • •PointlessOne :loading:
in reply to Curtis "Ovid" Poe (he/him) • • •EndlessMason
in reply to PointlessOne :loading: • • •@pointlessone
All code is the perimeter.
@ovid
T Alex Beamish
in reply to Curtis "Ovid" Poe (he/him) • • •I'm in the 'it depends' crowd. If it's suspect, but I can live with it, it gets logged and I move on. If it's completely garbage, it gets logged and ignored. The only time I have exceptions is when someone needs to look at the data and decide what to do in this specific case.
I had one like this recently -- "Really? This script's been in service for six years, running every half hour, and that's the first time we've seen this error?" I implemented a fix, and things started up again.
Nik
in reply to Curtis "Ovid" Poe (he/him) • • •Paul Evans
in reply to Curtis "Ovid" Poe (he/him) • • •Red_Shirt_no2
in reply to Curtis "Ovid" Poe (he/him) • • •Barrett
in reply to Curtis "Ovid" Poe (he/him) • • •Mark
in reply to Curtis "Ovid" Poe (he/him) • • •that’s such a “there be dragons” question 😄
I tend to always throw exceptions when receiving bad data from an initialization-like call, but usually do false returning internally for little stuff.
But if I have to hand data back away from my stuff I’ll throw an exception too if something goes wrong handing it back before exiting.
If it’s something complex where I can be confident exceptions are handled I’ll use them everywhere. There’s a bit of a twisted freedom in that.
Konrad
in reply to Curtis "Ovid" Poe (he/him) • • •