Hacker News new | ask | show | jobs
by Orphis 32 days ago
And the day you add a way to batch import request through another code path, you may forget the validation.

Having it in the lower layer is correct, a proper optimizing compiler should be able to detect there's a single code path to the function and that the checks have already been done, skipping the second check.

2 comments

Alternatively, the code could be written in the style of parse, don't validate[1]. However I've never had a coding LLM preemptively suggest that.

[1]: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...

Well - this would be an example of defensive programming and by that logic catering for this "what if" is the way to go. LLMs were correct all along!