Live data from Hacker News

It's not a hack to satisfy known requirements

charemza.name

21–30 of 60 posts

Re: It's not a hack to satisfy known requirements

#21
This piece of advice:

> Remember you can still add in that complication tomorrow

is directly undermiend later with:

> When should you create stuff just in case? > ... > 1. There is a reasonable chance it will be useful later > 2. It will be difficult to add in later > 3. It won't meanginfully slow down the meeting of more likely requirements

whenever i've pushed to overengineer its because i've developed a strung hunch that points 1 and 2 are true and i'm being defensive about my time and effort next week.

and if you're not allowed to push back because of 1 and 2 it's a sign of some sort of organizational problems where product folks sit at the top of the hierarchy and hand down dictates to builders without consulting with builders as equal partners.

Re: It's not a hack to satisfy known requirements

#22

It's all pretty solid except for the part about OO. Inheritance almost never works in "the real world" but I find being able to tie functions to the data they're expected to work on to be pretty helpful. It's sort of like typing, really, functionX can only take FooBar variables vs making methodX on class FooBar. Like everything else you can "do it wrong" and you shouldn't be a slave to any particular software ideolog…

But then the function x data mapping isn't 1 to 1 in most cases, which is often why inheritance is used.

IMHO sperating data formats and functions works decently enough, interface/protocol/duck typing are more elegant than OO classes.

As a real world image, a barcode scanner could be applied to anything that has a barcode, regardless of what that thing is. And I'd wager 99% of what we're trying to do fits that mold. When authentifying a user, the things that matter will be wether it's a legitimate call, and whether the user is valid. Forcing that logic I to classes or filtering by use type quicky becomes noise IMHO.

Re: It's not a hack to satisfy known requirements

#23
post #9

This is a great article, and I largely agree but I feel like we're giving ourselves an excuse to be lazy. Because I've absolutely seen this principle swing in the opposite direction, where someone writes slop code, without ever having had a real conversation with the end user(s) and consequently the software goes out the door without having considered top 5 most common edge cases that would have been so obvious if a…

It's easier to fix underengineering than overengineering so I still err on the side of the former.

Re: It's not a hack to satisfy known requirements

#24
post #16
post #10

I find that strong typing often obviates the need for unit tests. Software breaks when data transforms in a way that typing can't solve. When data goes across a wire, or into a database, it leaves your space. Anything you do to your code risks breaking it. Integration tests solve that, but at a very high cost. I don't have a great solution for that. It just comes down to experience: how do things change over time? Yo…

> strong typing often obviates the need for unit tests Do languages like Java have strong typing? I thought so, but I can’t reconcile that with the belief that unit tests in Java would be unnecessary.

It's reasonably strong, so that on practice you can trust it to verify the properties it verifies. (Though, it's not completely flawless in theory.)

It's also static, so your types declarations will replace tests.

But it's extremely inexpressive, so you can declare very few properties, and so it will replace very few tests.

And it's inflexible, so it will get on your way all the time while you program.

Anyway, I can almost guarantee you the GP wasn't talking about Java.

Re: It's not a hack to satisfy known requirements

#25
> Remember that code that clearly solves just those problems is in no way a hack.

I think you can’t stress this point enough. In my experience anything that is not implemented by any norm or „clean“ or in an unusual way is considered a hack. Even if it perfectly solves the problem with the least amount of cruft to it. That makes me sad.

Re: It's not a hack to satisfy known requirements

#26
> One of the worst pieces of advice that I ever received was that every function should be unit tested.

Obviously not every function should be -- many are so obvious and straightforward that there's nothing to test -- but every function that does anything vaguely "algorithmic" should be. Unit testing is really important for catching logic errors.

> Instead, write higher level tests close to the client/user facing behaviour that actually give you protection against breaking things unintentionally

Yes, these are good. But they're a different kind of test. There are tests for correctness, and tests that the program runs. You need both.

In fact, sometimes you even need to split up functions smaller than they otherwise would be, just so you can test an inner logic portion independently.

Re: It's not a hack to satisfy known requirements

#27
post #16
post #10

I find that strong typing often obviates the need for unit tests. Software breaks when data transforms in a way that typing can't solve. When data goes across a wire, or into a database, it leaves your space. Anything you do to your code risks breaking it. Integration tests solve that, but at a very high cost. I don't have a great solution for that. It just comes down to experience: how do things change over time? Yo…

> strong typing often obviates the need for unit tests Do languages like Java have strong typing? I thought so, but I can’t reconcile that with the belief that unit tests in Java would be unnecessary.

There's no single definition of strong with respect to typing, but I would probably put Java into the weaker of type systems, though it has gotten better over time. You can usually tell by how many casts you see in the code, and with most java codebases I see them everywhere. The pervasive nulls and untyped arrays are also huge red flags.

Re: It's not a hack to satisfy known requirements

#28
> Avoid Object-Oriented Programming

Yeah, no. Every time I saw code written by someone who attempted to avoid OOP it ended up with passing a huge 'context' parameter to most functions, effectively reinventing Python's OOP but worse.

Use pure functions as the starting point, but when you find yourself start passing complex structure around (any abstract word in parameter names, like 'context', 'data', 'fields' is a sign for that) just use OOP.

Re: It's not a hack to satisfy known requirements

#29
post #10

I find that strong typing often obviates the need for unit tests. Software breaks when data transforms in a way that typing can't solve. When data goes across a wire, or into a database, it leaves your space. Anything you do to your code risks breaking it. Integration tests solve that, but at a very high cost. I don't have a great solution for that. It just comes down to experience: how do things change over time? Yo…

> I find that strong typing often obviates the need for unit tests.

There are many ways that software can fail, and unit tests cover some of them. They don't remove the need for unit tests at all, but they do reduce the number of them needed (because you no longer need to test the things that strong typing handles).

Re: It's not a hack to satisfy known requirements

#30
post #10

I find that strong typing often obviates the need for unit tests. Software breaks when data transforms in a way that typing can't solve. When data goes across a wire, or into a database, it leaves your space. Anything you do to your code risks breaking it. Integration tests solve that, but at a very high cost. I don't have a great solution for that. It just comes down to experience: how do things change over time? Yo…

> I find that strong typing often obviates the need for unit tests. Can you expand? Because my experience is they are totally orthogonal. For me, unit testing is to ensure the function's algorithm is correct. You verify add(2, 3) == 5 and add(1, 2, 3) == 6 and add(2, Null) == Null. But you don't generally write unit tests that tests how a function behaves when you pass an unexpected type. Nobody in my experience is t…

> Nobody in my experience is testing add("a", FooObject) for a function only meant to take ints or floats, to make sure it only takes ints or floats.

If it's a dynamically typed language and you want to be sure that your method throws an error on invalid types (rather than, say, treating the string "yes" as a boolean with a value of true), then unit tests are a good use for this.

I would argue that failing fast (for cases like that, where an input "could" be treated as the type you want, but almost certainly the caller is doing something wrong) is a positive thing.

Post reply on HN