Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
" business logic is sound "
Can't be that sound if it doesn't work.
" Sanitize input first and never trust it "
Good lesson to learn. -
That's just how maps work, it's not "corrupted" data. "12345" and "12345 " are two different things and should map to different values.
Definitely not sound business logic if you expected differently. -
@RememberMe My business logic detects if my input has two equal entries. I don't consider something with a space as valid input. A space doesn't belong in my business domain, for my input should be a list of strings that have only a hash but no spaces.
I should have written a comparator/compareTo, perhaps. -
Just for clarification, what does sound mean in this context? There are literally 42 translations for sound
-
@delegate212 it’s not used in the yo though, is it?
I thought it’s an Irish think only. -
@EaZyCode grand, cool, okay.
Like: had fun with that guy, he’s sound.
Or: if you give me n€, that’s sound,
Or: if you can’t make it tonight, that’s sound. -
@CaptainRant You should've stripped spaces within the presentation layer, that's what you should've done. Don't bloat business logic with input sanitization.
-
@EaZyCode It's in the general context, as in:
That my code should work in all scenarios. That the logic of the routine is valid and also works in all cases. If the logic is valid (it checks for all duplicates and only works with non-duplicates), that doesn't mean it's sound (works in every situation, with every input). My mistake was assuming my code would work in all given situations as they appeared narrow to me (vague and imprecise thoughts).
This video should provide some clarification on what I mean:
https://youtube.com/watch/... -
@Lor-inc Yes, I know that, but sometimes you're Mr. backend and you don't have control over what the frontend people do.
-
@CaptainRant I mean, normally backend splits to presentation and business logic in larger codebases.
-
@Lor-inc I know - and I have that. I'm in charge of the MVC in my project but I'm not in control of the input (the actual files that get dropped into my UI etc).
-
This is part of the learning curve. The one thing you can't control are people doing data entry.
You're on the wrong track however. Sanitisation should be a last resort. Validate instead. -
@CaptainRant I see. In any case, I think you should sanitize input the moment you get it. If you can't trust frontend or pres, add an intermediate "frontend fixes" layer that does everything frontend should.
-
Sanitize input first is a lesson learned? I hope you haven't missed all those other lessons!
Related Rants
-
nachocode18If you had one language One framework To code everything you want Would you learn it or let it pass His cod...
-
perplexkid5Junior Dev does npm install, Opens LinkedIn profile and adds Node.js in skills.
-
Alpham0use9Junior job requirements be like: Required: 5 year experience in Php, 8 years experience in JavaScript, Masters...
It reaaaally annoys me when my business logic is sound but the data is corrupted.
For example, find duplicates in a HashMap<String>.. but I didn't take into account the input could contain a space either before or after.. so I end up wondering: if a HashMap only contains unique keys, how come the count of items in the map is the same as the count of the input keys?! Well.. spaces were the culprit.
"12345" != "12345 ".. and therefore the Map sees it as two distinct keys..
What an annoying bug.
Lesson learned: 1) Sanitize input first and never trust it. 2) Never make assumptions
rant
junior dev
lessons learned
sanitize input