this post was submitted on 28 Mar 2025
0 points (NaN% liked)

Programming

28531 readers
884 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 3 years ago
MODERATORS
top 6 comments
sorted by: hot top controversial new old
[–] syklemil@discuss.tchncs.de 0 points 2 years ago (1 children)

I feel I gotta point out it's a pretty funny example—email comes up so frequently as a thing that you're recommended to neither parse nor validate, just try to send an email to the address and see if it works. If you need to know that it was received successfully, a link to click is the general method.

But "parse, don't validate" is still a generally good idea, no matter the example used. :)

[–] thenextguy@lemmy.world 0 points 2 years ago (1 children)

I don't see it. I would much prefer to validate early rather than late. The example of 'other code might validate it differently or not at all' seems specious. I don't want invalid information "deep within the bowels of the system".

[–] syklemil@discuss.tchncs.de 0 points 2 years ago (1 children)

Parsing is a way of "validating early". You either get a successful parse and the program continues working on known-good data with that knowledge encoded in the type system, or you handle incorrect data as soon as it's encountered.

[–] thenextguy@lemmy.world 0 points 2 years ago (1 children)

I understand the concept. I just disagree that it's a good idea.

[–] zygo_histo_morpheus@programming.dev 0 points 2 years ago (1 children)

Why do you think it's a bad idea? Both you and OP are in agreement that you should validate early, which seemed to be what your first comment was about. Is it encoding that the data has been validated in the typesystem that you disagree with?

[–] thenextguy@lemmy.world 1 points 2 years ago

I disagree that parsing is validating. For example, you could give me a valid ISO date time string, but I want a shipping date and you gave me something in the past. It parses, but is not valid.

I disagree that validating early is bad because some other part of the code might also validate later and possibly do it differently. Yes, that's bad, but not a reason to not validate early.