In school I wrote parsers. At work I have done it but it's rare.
In fact if you write commercial code you'll often find that the code that you rely on that is like that weirdly gets concentrated in open source libraries which you will be testing only indirectly.
Certainly when writing commercial code I find that the majority of bugs lurk in the interstitial spaces between subsystems I am integrating or in misunderstandings about how the overall system or subparts of it are supposed to behave.
And property tests are not much help there and unit tests are often a hindrance (because theyre as likely to bake in wrong assumptions).
TDD is some help with this but only if A) it's paired with BDD to exorcize specification bugs and B) done with integration tests that exercise all parts of the system together.
wasBusinessDay(date): Date.dayOfWeek(date) not in (Date.Saturday, Date.Sunday)
Which is as trivial as yakubin's example, but can fail for more, and much more nuanced, reasons - and no, you are not, in general, going to find an off-the-shelf answer to the question of whether your particular business was operating on a given day.Both your claim that a big problem is things not working as they are supposed to[1], and the fact that the same old basic security problems get repeated in every new platform that comes along, show that libraries have not, in practice, been any sort of panacea for business software.
[1] I suspect you are referring to application code rather than library code, but either will do for the point I am making here.
I built a property testing library back in the day when I made a library for creating UIs. I was then able to write tests like
* Given an arbitrary UI
* And an arbitrary up/down/left/right list of user direction (this was the only way of navigating)
* If they press a direction and the focus moves, pressing the opposite direction takes them back to where they were before
This uncovered bugs in interfaces like this with 3 items, bottom left is in focus and you press right. Now press left, users probably want to go back to the bottom left rather than top left.
┌─────┐ ┌─────┐ ┌─────┐ ┌──────┐
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
└─────┘ │ │ └─────┘ │ │
│ │ ────► │focus │
┌─────┐ │ │ ┌─────┐ │ │
│focus│ │ │ │ │ │ │
│ │ │ │ │ │ │ │
└─────┘ └─────┘ └─────┘ └──────┘
Another one was* Given an arbitrary list of API calls to add/remove/change the UI and user direction presses
* There is always only one item in focus, or no items at all
This actually uncovered a specification bug. We had two requirements
1. Always have an item in focus if there are any that can be in focus
2. If you delete all the items, then add one back in, it's not focussed
Those conflict, but we never noticed, and even had passing unit tests for both cases.
I think property tests can map very nicely to the level of system description that we typically want. I'd love to see larger integration with BDD tools.
College students who start out by writing toy compilers, quicksort implementations and physics engines will often get a distorted view of what professional development is actually like.
If anyone is patronizing here it's you.
You face some hard decisions on that one. None of the error handling paradigms are good at handling the class of numeric errors that people really, really want to pretend don't exist because no matter what kind of error they throw they're a major pain to deal with correctly.
After discovering the bug, one may even write a branchless implementation of this function for performance without updating the test, and it will still be 100% coverage. But the arithmetic has "logical branches" which do not look like ifs, instead they generate qualitatively different results for different inputs.