Assertion Philosophy

LordFrith

Ars Legatus Legionis
25,252
Subscriptor++
Okay, I've been in a couple of recent discussions about how to best protect/guard behaviors. This kind of thing can happen across any number of languages, but my example is going to be based on a recent experience.

Basically, the questions is: should you only allow inputs you expect, or should you only ban inputs that cause problems the programmer couldn't have expected?

My most recent example is:

Code:
#!/bin/bash

is_test=${is_test:-false}

function do_something() {
  if "$is_test"; then
    echo "Doing the thing"
  else
    do_the_thing
  fi
}

So, in this case, the concern was, "Whoa! You are letting someone run any code they want in that statement." My answer was, "Yeah, and?" Basically, this is a script that you would only run as a test, that's not a common variable name, and it's not asking for any extra privileges. His point was, "You should prune off any possible bad behaviors at the start."

So, the question was, should that be turned into a number, and then compared with something like:
Code:
is_test=${is_test:-0}

function do_something() {
  if [[ is_test -ne 0 ]]; then
    echo "Doing the thing"
  else
    do_the_thing
  fi
}

Which is fine, but if you really want to run something unsafe on your machine, you pretty much can without this script in the way, anyway. But it gets to the philosophy I have seen repeated:

Code:
int move_item_from_a_to_b(const PositionType &a, const PositionType &b) {
  assert(a != b);
  ...
}

This code is a little more contrived, so my apologies. But this is the concept I want to get at. In that "move_item" call, we have a call that will force a physical change of position -- literally moving an item in physical space from one location to another. So, there are certainly needs to be 'safe' to make sure you don't get into bad physical realities. It's also unlikely that someone really wants to move something from a position to the same position.

But, my point is, it doesn't hurt. It's a no-op. There are potentially unimagined workflows that could benefit from having that no-op. And I see no reason to assert against it. The co-worker I was discussing with was of the point, "I see no reason to allow it, because I have no examples of why we would want it."

My issue is that when I'm in the middle of development, over-asserting is one of those things I have to constantly un-do. Which is even more painful if there are a bunch of tests confirming the presence of the asserts. His point is that in the middle of development, being stopped early when you are doing something you don't realize you are doing is a better result.

And thus, I turn to the "Wisdom of the Board". Are you a liberal coder or a conservative coder?
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
How do you know that's a noop? If a and b pointed to gigabytes of memory and your underlying copy library wasn't smart enough to check and bypass copies onto itself, you'd have an expensive "noop".

There are potentially unimagined workflows that could benefit from having that no-op.

Yeah... code that isn't written that might benefit from undefined/unknown functionality of this function. How would they benefit from a noop? What scenarios would you explicitly put a noop in? What scenarios would you put something in that may or may not be a noop?

Something else... assertions, in code/environments I've used, are debug only constructs. When compiled for release, they get removed so they don't help in production code anyway. We've tended to load up the function with asserts but not test directly for those as the behavior in debug and production would be different... during runtime, you could get unexpected inputs and the asserts wouldn't exist so you wouldn't see anything. If it were important enough to guard against those inputs because of bad/undesirable behavior, imo, they should be in actual code.
 

LordFrith

Ars Legatus Legionis
25,252
Subscriptor++
To the first point: this wasn't moving memory around. It was literally moving a robot arm. Physically moving from the same location to the same location is literally a no-op. For workflow purposes, you could imagine a situation where this "no-op" was done because the main loop was examine-move-retest, and so in this case, the "no-op" was done because I wanted to re-examine the same situation some few seconds later. That's an example -- not what ended up happening.

As for asserts being compiled out -- yes, typically. I made a more general approach to an "Assert" that people are comfortable with, while in this case we actually use a type of assert that isn't compiled out. But it's pretty much not important -- when the workflow that needed the situation came up, all the asserts for the condition then had to be removed for the tests that exercised it.

And that's my point -- do you over-protect against misuses of code the way you expect them to be used, or do you only add protections to situations that you know should not be done?

Also, I wouldn't call it "undefined behavior", as much as "not the intended use case".
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
It depends on what the software is doing. If it's critical and/or certain input values can cause or lead to damage of some kind downstream, then I'd probably put strong guards around it. Another example along these lines are that some languages allow you to do things like execute methods on null object references kind of like noops (it checks for you and if null, skips the method call). This allows you to do things like populate collections with a mix of valid object instances and nulls and then iterate over each thing in the collection as if they are all valid object instantiations without worrying about if some are null or not. I personally don't like that.

If it's something like an input parameter is a string that you are going to use as a filter in an SQL query to return some data, it depends on the application as well. You want to catch those type things early (like in input field validation) to give the user a message that the value is missing so that the user can provide the value instead of seeing an error/crash in the application. Applications that have users typically have to be guarded pretty well because users can, and will, put anything, everything, and nothing for required fields otherwise and an application crash is a significant negative appearance for your app. The same thing on things like webapis. Validate data upon receipt and return errors so the app can deal with them in a way that doesn't turn users off. In the past we've done things like have our inputs and outputs to third parties be in XML so that xsd can be written so we validate inputs before processing and outputs before sending and encourage our third party receivers to validate using that same xsd upon receipt. An xsd and a couple sample data files can save a *ton* of headache when integrating with third parties. If they're building something themselves, you give them the xsd and samples and they can work in parallel.

I guess that's usually how I classify it... if it can lead to something a user can see, particularly as a crash, then validate as early as possible and return status/feedback for the user to correct (this can be user input field validation on the web page, for example). Minimize negative impressions of the application (crashes). If it's something that runs as a backend service then probably not so much guarding because the inputs will already have (should have) a high degree if cleanliness already. I'd still likely wrap the highest level in a catch-all, last chance exception to log/report any unexpected errors and then deep down, use exceptions judiciously where they make sense (operations that can actually be recovered/retried) otherwise fail hard and fail often.

I don't subscribe to calling functions without a reason to call them, though. You can't always assume that the function will be the equivalent of a noop if the input parameters you give it aren't significant somehow. That's not to say that your above function wouldn't have good use... particularly if the positions its given aren't relative (they're absolute). Your function may be to "move to this location" because you need it to be there before performing the next sequence of movements. If the thing is already at that position, then it's a noop. I would consider that fine, though, as you are asserting that the robot must be at that absolute location, no matter what, before the subsequent sequence of operations are performed.
 

LordFrith

Ars Legatus Legionis
25,252
Subscriptor++
So I generally agree. A couple of minor differences:

First, if it is unknown user input, yeah, I'm going crazy with the checks and verification -- because I'm still likely to miss something even then. However, if it's an API for a programmer to call, I'm less likely to care. Especially if he can read my code if he wants. At that point, if he passes in a configuration I wasn't expecting, I don't really care.

Second, The example of a no-op was given as an example instead of walking through the 3 pages of design decisions for a certain system with the configuration described. Another example that may be more reasonable is having the robot move a disk from container type A to container type B, where the original design could see no reason to allow that transition if the two containers were the same, but later we realized that changing specific instance of the container would help us verify faulty equipment.

The original code disallowed the transition. It had assertions, and tests that checked those assertions. However, there was no physical harm that could come from it, it was just something that was originally wasn't expected to happen. Thus, disallowed.

My liberal coding would be, "Meh, if it's not going to cause a problem, don't add in a check to disallow it".
 

minnmass

Ars Tribunus Militum
2,087
Subscriptor
It all depends on the contractual behavior you want, and where the data is coming from.

Data coming from "outside the system" (eg., that a user types in or that comes in via RPC, etc.) needs to be verified as valid (whatever that means in context, from simple "is this a number" to "is this a valid state into which to put the system").

For library code, though I'd err on the side of not asserting.

If your "move" method guarantees that it will check with the arm to verify that it's in position "from", asserting that "from" and "to" are different is a bad idea: that might be how the caller has to verify that the arm is in the right place. It might also be a good way to do some initialization (eg., if the arm is a spinning-rust HDD arm, you might want to move from "parked" to "parked" on power up). In both of those cases, asserting that "from" and "to" are different is not helpful.

Additionally, if the contractual behavior of "move" is that calling it with the same source and destination is a quick no-op, it simplifies a lot of other code (you don't need many "if (from != to) { move (from, to}; }" checks outside of "move".

Finally, as LordFrith said, having the robot actually move a disk from "a" back to "a" might be the right thing: it re-seats the disk, which may fix a connectivity issue or allow the underlying OS to re-mount the disk if someone ejected it.

My 2 cents is that asserts belong in test code and constructors if you're using dependency injection (asserting that the injected dependency isn't null if the class depends on that state).
 

Lt_Storm

Ars Tribunus Angusticlavius
21,346
Subscriptor++
Your coworker is wrong, you generally shouldn't verify things that you don't require. The general rule for data verification is: be broad in what you accept and narrow in your output / store. This means that your script which only cares that the value is truthy rather than some specific value is better. After all, you do not know the future. Just because you can think of no reason that you would want it today is more of an indictment of your imagination. Some day, you will eventually find that you want to do something that you couldn't think of a reason you would want to do earlier. If you wrote that check in, then it will cause problems.

Of course, you should verify anything that is likely to cause problems later. The classic example of this is null checks, which should be done early and often. After all, if you have a value, you are probably expecting to use it. If it could be null, then you have to check before every time you use it. It is far better to represent the rare such situation using an Optional and then murderize every null input to cross your library interface using a runtime null check.

The second type of reason why you might want to verify an input is if it is something where a human mistake is likely. For instance, if you have a bunch of markdown files with metadata keys that affect their rendering, you might want to check that there are no unexpected keys. After all, an unexpected key is more likely to be a spelling error than something intentional. And you want to catch such mistakes during compilation and testing rather than once the system is deployed. Alternately, of course, any time a human enters data into the system, sanity checks are in order.

The third reason to assert something is for security. This goes for any data which comes from an untrusted bit of code or network. Sanity checks of such inputs are, obviously, a must. Though, detecting injection attacks isn't the goal here. Those should be handled by testing with injection strings. This is more about spending some time thinking about what the effects of processing a megabyte long input are likely to be, and establishing sane limits to prevent them.

For the robot arm, there are probably some physical possibility and safety checks that need to be done and that should be it. Always assume that your library is going to be used by someone inventive who is going to come up with use cases you never imagined. Try not to make that person hate you.
 

MilleniX

Ars Tribunus Angusticlavius
8,139
Subscriptor++
Lt_Storm: the entire world of people actually writing network protocols has pretty much soured on Postel's principle, as producing massive compatibility burdens, immense barriers to entry for new implementations, and many opportunities for security issues in under-exercised portions of code. Where strictness is feasible, it seems to be much preferred.

That said, I don't think the argument is all that applicable one way or another to library APIs, rather than services facing outside clients.
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
Lt_Storm: the entire world of people actually writing network protocols has pretty much soured on Postel's principle, as producing massive compatibility burdens, immense barriers to entry for new implementations, and many opportunities for security issues in under-exercised portions of code. Where strictness is feasible, it seems to be much preferred.

Exhibit A: HTML
 

Lt_Storm

Ars Tribunus Angusticlavius
21,346
Subscriptor++
Lt_Storm: the entire world of people actually writing network protocols has pretty much soured on Postel's principle, as producing massive compatibility burdens, immense barriers to entry for new implementations, and many opportunities for security issues in under-exercised portions of code. Where strictness is feasible, it seems to be much preferred.

Exhibit A: HTML

A well proven protocol which we use to run basically everything primarily because HTML Headers aren't overspecified. Imagine, for a moment, if HTML specified which headers could exist. That *is* technically feasible, but it would be a nightmare. The protocol wouldn't have been successful. Moreover, experience teaches that, for instance, checking that an input matches a schema exactly with no extra fields tends to make systems less useful. The point here is to achieve the balance between verifying things that your application / library cares about and being open on things that it doesn't care about. Many of the success stories at Amazon were successful primarily because they didn't overspecify and that meant that when other systems added new data they didn't have to change all the systems between the two systems that cared about that data.

Being strict for the sake of being strict is foolish. You should always have a reason for the things your schema requires. For instance, many times someone tries to deal with HTML injection by being strict about what they accept. The problem is that this requires that you never miss something that HTML will interpret. The number of HTML injection errors that occur because the regular expression used to banish HTML tags was wrong is vast. They would have been better off to just escape appropriately. They could even write a type system, static checker, or runtime routine which verified that only escaped text ended up in the HTML document. They wouldn't have been insecure. <key point and example> Moreover, they made their system less useful because nobody could write an example of what HTML code looks like. </key point and example>
 

LordFrith

Ars Legatus Legionis
25,252
Subscriptor++
Imagine for a moment all the person-millennia that have gone into deshitting shitty HTML because of its shittiness... ;)

There were many stricter protocols, that, amazingly, the developers didn't add in enough capabilities to and this couldn't expand.

On the bright side, nobody spends any time writing those anymore.
 

Lt_Storm

Ars Tribunus Angusticlavius
21,346
Subscriptor++
Imagine for a moment all the person-millennia that have gone into deshitting shitty HTML because of its shittiness... ;)

There were many stricter protocols, that, amazingly, the developers didn't add in enough capabilities to and this couldn't expand.

On the bright side, nobody spends any time writing those anymore.

Yep, despite all its flaws, HTML works, and has left many dead protocols in its tracks. Were it not for the open nature of the protocol's schema, it wouldn't even have been worth deshitting.

edit: oh, and beware the contention that nobody spends any time writing those anymore. You might invoke someone from one of the dimensions unfortunate enough to have to use them and be forced to hear of the monsterities they have created working around the lack of capabilities.
 

Nimdok

Ars Scholae Palatinae
1,214
Which is fine, but if you really want to run something unsafe on your machine, you pretty much can without this script in the way, anyway. But it gets to the philosophy I have seen repeated:

Code:
int move_item_from_a_to_b(const PositionType &a, const PositionType &b) {
  assert(a != b);
  ...
}

This code is a little more contrived, so my apologies. But this is the concept I want to get at. In that "move_item" call, we have a call that will force a physical change of position -- literally moving an item in physical space from one location to another. So, there are certainly needs to be 'safe' to make sure you don't get into bad physical realities. It's also unlikely that someone really wants to move something from a position to the same position.

But, my point is, it doesn't hurt. It's a no-op. There are potentially unimagined workflows that could benefit from having that no-op. And I see no reason to assert against it. The co-worker I was discussing with was of the point, "I see no reason to allow it, because I have no examples of why we would want it."

I definitely would not assert in this instance because there's no telling where the values for the params come from. You don't want every caller to have to check before invoking the function--better to do a check inside the function and return if the values are the same. For example, what if a function "default_location()" were called to supply parameter "b", and it just happened to match "a" at the time it was called?

The program is gonna _crash_ if any caller of the function fails to do that check and hits that harmless edge case. It creates undocumented/implicit work for callers.
 

minnmass

Ars Tribunus Militum
2,087
Subscriptor
Which is fine, but if you really want to run something unsafe on your machine, you pretty much can without this script in the way, anyway. But it gets to the philosophy I have seen repeated:

Code:
int move_item_from_a_to_b(const PositionType &a, const PositionType &b) {
  assert(a != b);
  ...
}

This code is a little more contrived, so my apologies. But this is the concept I want to get at. In that "move_item" call, we have a call that will force a physical change of position -- literally moving an item in physical space from one location to another. So, there are certainly needs to be 'safe' to make sure you don't get into bad physical realities. It's also unlikely that someone really wants to move something from a position to the same position.

But, my point is, it doesn't hurt. It's a no-op. There are potentially unimagined workflows that could benefit from having that no-op. And I see no reason to assert against it. The co-worker I was discussing with was of the point, "I see no reason to allow it, because I have no examples of why we would want it."

I definitely would not assert in this instance because there's no telling where the values for the params come from. You don't want every caller to have to check before invoking the function--better to do a check inside the function and return if the values are the same. For example, what if a function "default_location()" were called to supply parameter "b", and it just happened to match "a" at the time it was called?

The program is gonna _crash_ if any caller of the function fails to do that check and hits that harmless edge case. It creates undocumented/implicit work for callers.

I 99% agree.

Depending on the circumstances, I could definitely see giving `move_item` an optional (set of) flag parameter(s) to control what to do if "from" is equal to "to"; reasonable options could include:
  • throw an exception
  • do nothing (return immediately)
  • physically move the thing from "from" back to "from" (eg., re-seating the thing)
  • info-log and perform any of the above

But, 99% of the time, the caller should make that decision. Barring the case that one of the options has a high likelihood of causing physical damage to the thing that's physically moving, throwing an exception if "from" and "to" happen to be the same is the least likely outcome I (as the caller) would expect, thus it violates the Principle of Least Surprise.

If throwing an exception is absolutely essential for some reason, and the language allows it, please at least use a typed exception that I (again, as the caller) can catch or, at the very least, can see in the crash report.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
Postel's law is crappy for APIs within a closed entity. I personally think they are dubious in the modern open soure world too because rapid user feedback is still possible.

If someone passed in something you don't expect then this is an opportunity to:

A) detect a bug
B) Detect undefined behaviour, and define it
C) Detect a feature that is useful to your users you may wish to support explicitly

If you detect those and throw/abend/raise/etc nicely indicating that you think the operation makes no sense, indicate a possible solution for any known issues that would result in the know (A) conditions, indicate the place to ask for this thing to actually be a supported thing you can improve your program, or improve other people's programs.

Change is good when well directed and managed, allow for change, but make it controlled.

If enough of your users complain about a no-op being treated as a problem in your specific scenrio you can then either:

1) Just allow no-ops with an explicitly bit of documentation saying what the no-op will do (for example in the robot case it may or may not pass on the pointless command to the actual arm, that's something to document)
2) Provide an alternate call/parameter/mode that allows for no ops silently, provide a means for code to detect these no-op happening and being made aware of them
3) Still disallow it and have a chat with all the stackeholders to agree this is worth the cost even if they find it annoying

Or insert some 4 I've not thought of (that's the benefit of having these sorts of conversations)
 

minnmass

Ars Tribunus Militum
2,087
Subscriptor
Postel's law is crappy for APIs within a closed entity. I personally think they are dubious in the modern open soure world too because rapid user feedback is still possible.

If someone passed in something you don't expect then this is an opportunity to:

A) detect a bug
B) Detect undefined behaviour, and define it
C) Detect a feature that is useful to your users you may wish to support explicitly

If you detect those and throw/abend/raise/etc nicely indicating that you think the operation makes no sense, indicate a possible solution for any known issues that would result in the know (A) conditions, indicate the place to ask for this thing to actually be a supported thing you can improve your program, or improve other people's programs.

Change is good when well directed and managed, allow for change, but make it controlled.

If enough of your users complain about a no-op being treated as a problem in your specific scenrio you can then either:

1) Just allow no-ops with an explicitly bit of documentation saying what the no-op will do (for example in the robot case it may or may not pass on the pointless command to the actual arm, that's something to document)
2) Provide an alternate call/parameter/mode that allows for no ops silently, provide a means for code to detect these no-op happening and being made aware of them
3) Still disallow it and have a chat with all the stackeholders to agree this is worth the cost even if they find it annoying

Or insert some 4 I've not thought of (that's the benefit of having these sorts of conversations)

And, this is exactly why I think Postel's Law is of such high import.

We all know there's never time to refactor code or fix the little niggling annoyances: there are Features to develop and Customer Facing Bugs to fix. So, when I come across this "move to" library method that causes my app to crash-to-desktop if I forget an equality check, I take the logical next step: write a wrapper. So, now all of my code is using "minnmassMoveTo()" which handles the equality check and may have flags for determining how to handle an equality situation. And, now we have "move to" and "minnmassMoveTo" floating around the code base. Then, LordFrith (chosen by virtue of being the OP) comes in to make a change but misses "minnnmassMoveTo", so writes a wrapper "LordFrithMoveTo", which may or may not take flags, but certainly doesn't use the enum of options I do.

... okay, I'd probably call it "safeMoveTo", but the point stands if LordFrith makes "equalitySafeMoveTo".

If there's a physical safety concern about "move to" having the same "from" and "to" locations, definitely put a guard in "move to" to catch that. And, crashing to desktop might be the right thing in that scenario (despite it leaving the machine in an unknown state; maybe the app has to start with a "reset" command that puts everything into an initial state?).

But, I still maintain it's better to design the library in such a way that there's some option between "equality checks around every call" and "there's a crash-to-desktop trigger hidden, lurking, behind the scenes". I'd personally lean towards a flag enum: the signature doesn't have to change if more options are added and it's immediately clear at the call site what the expected deviation from normal behavior is, but I typically work in C# where there's language support for that.
 

minnmass

Ars Tribunus Militum
2,087
Subscriptor
Postel's law says, when you don't have a reasonable idea what the right behaviour should be then "guess" I think that's a really bad idea.

I read Postel's as "don't do surprise your consumers". Crashing to desktop is always surprising. Sometimes, though, it is the right course of action (eg., when not doing so will corrupt more data or cause physical damage).

Taken in isolation, a "move" command that crashes my app to desktop is bad because it's highly surprising and it will implicitly require a host of "if (a != b) { move(a, b);}" boilerplate.

If the library is intentionally ... "brittle" is probably the best word ... and any of the calls that involve moving things will fail an assert in "bad" conditions, then that is a library I don't want to use, but it's one in which "move" crashing if the "from" and "to" are the same might not be surprising.

So, it depends on the contract the library provides; maybe, if everything else throws, "move" throwing isn't the worst thing. I still think it's begging for a wrapper that lets you off the hook for the "if (a != b)" boilerplate, though. But, if some commands throw, all commands should throw: be consistent.

Again, IMO, a much better interface is one in which the caller can pass in an argument (or flag list) that determines how potential errors are handled, with exceptions being left for truly exceptional states (eg., if the connection to the arm is lost, that's definitely cause for an exception). The method should return either a bool indicating success/failure or some other return value that indicates why the failure happened. But, flow-control via exception (which is fundamentally what's being encouraged with "move" throwing) is a major code smell.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
libraries can, and should, change. Libraries might even be implemented initially be people who _have sufficient context_ to decide a reasonable behavior that is acceptable to most/all their clients (in this case they very well might) they might even go out and ask their clients in advance what they would like and do that (or discover it was fairly bimodal, so redesign the API to accommodate it in advance).

If you don't know, don't guess. Postel's law _mandates_ you guess. This is not okay IMO and, within a company environment, I have found vast numbers of examples where someone doing so has caused problems, especially when they pick something really wrong and people have started to depend on that flawed behavior.
 
D

Deleted member 43669

Guest
Asserts have a cost and a benefit. Write them when benefit > cost.

I wouldn't assert stuff my function doesn't care about. I wouldn't assert things that will crash a few lines below, if the crash is good enough.

I would assert stuff that will cause stuff to misbehave if I don't assert.

That is, under my current implementation, my function will return invalid results if I pass in an empty list as a parameter? Assert. Will I get an index-out-of-bound exceptions which will result in a good enough error message? Don't assert. Will it result in a useless error that will make someone tear his hair out finding out what happened? Assert.

...

To me, Postel's law is about doing extra effort to deal with broken input. Writing more complex parsing code to deal with malformed input. IMHO, that's a bad idea most of the time.
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
If you don't know, don't guess. Postel's law _mandates_ you guess. This is not okay IMO and, within a company environment, I have found vast numbers of examples where someone doing so has caused problems, especially when they pick something really wrong and people have started to depend on that flawed behavior.

Not that this is because of Postel's Law, but along the lines of entrenched workflows based on flawed behavior...

One of my first lessons in commercial software (my first job out of college)... the software suite I was working on was written by Fortran programmers learning C while they were writing it. Without a lot of story... there was a routine that would take basically an array of line segments and a polygon and was supposed to return basically multiple arrays of line segments based on which line segments were outside the polygon and which were in it... and breaking line segments into multiple line segments where/when a line segment actually intersected an edge of the polygon. So... input a single line segment that started outside the polygon, ran through it, and exited the other side would return an array of three arrays of line segments (each with one line segment in it)... the first array would have a single line segment from the start up to where it intersected the polygon, the second array would have a single line segment from the edge of the polygon to the other intersection of the original line segment with the polygon, then the third array would have from the edge of the polygon to the original end/termination point of the original line segment.

Anyway... that routine was not done 'mathematically'. It was all sorts of edge cases and stuff... it was literally a few thousand lines long. Some of the complex code being when a line segment point was very close to the edge of the polygon or the line passed through a vertex in the polygon. There were lots of bugs in the code... particularly one due to floating point issues... it was possible to 'split' a line but then because floating point, think it needed to split again... and it would get into an infinite loop of splitting the line segment into an infinite number of basically zero length line segments.

Anyway... I spent a few weekends of my own rewriting the routine using math. I even tested it against all the known bugs (outstanding and regression). I presented it to management and they were surprised... and my manager said they'd get back with me. A while later, they came back and said that my fixes wouldn't be put in because it was "too big of a change" and would require a lot of testing. *Additionally* (and more to the point here) was that customers had built lots of functionality on top of the existing (flawed) functionality that either depended or was cognizant of that behavior and behaved accordingly to their needs... these changes would likely cause a few customers to have significant issues. So... my routines were shelved, never to see the light of day.

It was a tough learning experience, but a valuable one early in my career.
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
To me, Postel's law is about doing extra effort to deal with broken input. Writing more complex parsing code to deal with malformed input. IMHO, that's a bad idea most of the time.

Strike through mine... but this is exactly how I see it. More complex code carries with it the potential to introduce more flawed/unexpected behavior... which will require more complex code... which....

And it will also likely introduce more edge cases, more unexpected behavior, etc. in each iteration of dealing with more complexly flawed input.
 

Nimdok

Ars Scholae Palatinae
1,214
Anyway... I spent a few weekends of my own rewriting the routine using math. I even tested it against all the known bugs (outstanding and regression). I presented it to management and they were surprised... and my manager said they'd get back with me. A while later, they came back and said that my fixes wouldn't be put in because it was "too big of a change" and would require a lot of testing. *Additionally* (and more to the point here) was that customers had built lots of functionality on top of the existing (flawed) functionality that either depended or was cognizant of that behavior and behaved accordingly to their needs... these changes would likely cause a few customers to have significant issues. So... my routines were shelved, never to see the light of day.

It was a tough learning experience, but a valuable one early in my career.

I hope the lesson learned was related to communication, because if you wrote a version that fixed many known issues it seems like the least they should have done was exposed the less buggy method under a new function name or version of the API.

As one of their customers I would be pretty upset at knowing they were withholding fixes.
 
D

Deleted member 43669

Guest
To me, Postel's law is about doing extra effort to deal with broken input. Writing more complex parsing code to deal with malformed input. IMHO, that's a bad idea most of the time.

Strike through mine... but this is exactly how I see it. More complex code carries with it the potential to introduce more flawed/unexpected behavior... which will require more complex code... which....

And it will also likely introduce more edge cases, more unexpected behavior, etc. in each iteration of dealing with more complexly flawed input.

Yeah. To give a recent example, we are making a very expensive (100 USD/user/month) SaaS at the core of our company which provides a CRUD API. When you create a row in a table using this API, if you specify a field which does not exist... it will try to guess the correct field... and it will actually sometimes guess correctly. However, when you *update* a row, it doesn't seem to do so, and it drops silently the field.

This already caused us a bug (fortunately, low impact). Of course, this means that our tests were not covering everything, but still...