But someone posted some actual code, it had a switch statement, only 3 case options, about 7 lines and if the switch didn't hit, throw exception after
"I would be careful with that switch, it looks like a code smell, this is how I would do it: 2+ interfaces, 3+ classes, abstract this, factory that and over 100 lines of code.
I just refuse to believe a simple switch that everyone can understand in about 1 second is not the better solution to some complex code, even if it does use a "pattern"
You mean visualize with a tool, or in your head? If the former, I'd love to know of a tool for visualizing code flow.
If the latter, then I think a switch - with entry and exit points, and all code paths clearly visible together on one screen - is much easier to visualize than an implicit branching hidden behind interfaces, requiring you to jump around definitions of several objects.
When I said visualize, I meant primarily in the programmer's mind, but there are other tools that help. Code coverage tools ensure that all branches of code are tested, but fail to ensure that all permutations of all branches get tested. This is something where fuzzing tools can attempt to ensure that all branches are taken, but will quickly run into the limitations of the underlying machine if the cyclomatic complexity is too high.
Beginning programmers learn flow control very early in their development. Most will also learn fairly quickly that creating a rat's nest of ifs and switches can become difficult to reason about. It's for that reason that we learn abstractions that help us increase the complexity of the tasks we can solve without increasing the complexity of the code we have to understand.
That is certainly true, but it is equally true of any mechanism for making those decisions. With some mechanisms, like if-else and switch-case, the decisions are explicit. With others, like virtual function dispatch, the decisions are implicit. Either way, the decisions are still being made and the combinatorial properties of multiple decisions are still the same.
I think objectively the code is better for it but sometimes it takes more social sophistication than I possess. I end up spending too much time talking in post mortems and it all sounds like 'I told you so'
However, I think GP's point is valid. If during a code review I have a switch and it makes no sense to abstract it, I'd smack the reviewer on the head if he/she wants me to "fix" it.
From my perspective all three tried to solve maintainability. OOP via encapsulation and standardisation, functional via uncompromising standards, and TDD via validating each small subsection of the solution.
They all "work" if you commit to them enough. But none of them work when you half arse them. So instead of people working hard they move on to the next "solution" because the last solution required too much effort (TDD is definitely a victim of this, considering how much work it requires).
PS - People being "anti" something are just as religious as the people being "pro" something, except the anti people often have a smug sense of superiority. See the people arguing against GOTO in all and any circumstances in spit of how little sense their arguments make.
This sounds dangerous. It gives rise to the attitude that if X doesn't work you are just not doing it enough. Instead of accepting that maybe it's not the right approach to this particular problem.
1) Unit testing/TDD, specifically setting things up where I am able to run a unit test in less than a second on any code I'm working on has been a huge productivity boost vs. running a whole suite periodically
2) Immutable variables (or generally avoiding mutation)
3) SRP and cyclomatic complexity reduction
4) Pattern-matching (Elixir/Erlang) which also reduces the amount of branching in code and thus its depth (reducing cyclomatic complexity further)
5) FP (which incorporates (2) and (4) plus generally constraining side effects and I/O to the smallest part of the code possible, and leaving the rest non-side-effecting)
I have done scrum, but I haven't seen it as directly effective as these other things, it's more for effective PM IMHO.
"My pragmatic summary: A large fraction of the flaws in software development are due to programmers not fully understanding all the possible states their code may execute in. In a multithreaded environment, the lack of understanding and the resulting problems are greatly amplified, almost to the point of panic if you are paying attention. Programming in a functional style makes the state presented to your code explicit, which makes it much easier to reason about, and, in a completely pure system, makes thread race conditions impossible."
http://www.gamasutra.com/view/news/169296/Indepth_Functional...
Re-thinking everything for every project is wasteful. Sometimes you already know a way to do a project that works for you. Sometimes that way is mirrored by a lot of other people.
Other times you are selecting these things because it's a common thing to talk about and when you're teaching people the project, you can prime their learning by telling them to expect these models and methodologies in this project.
The mistake IMO is making the religion industry-wide when really you'll be lucky to implement it consistently just in your company/project.
Joel Spolsky covered this fairly well in his piece on McDonald's-style software. The best way to write a single program is to master programming, and develop alone or in a small group of masters, and build a beautiful and enduring tool with whatever practices suit you best.
But none of that can be packaged up and passed around to new programmers on demand. It takes time to master, and it certainly can't be smoothly overseen by someone who never learned it. The best way to get 100,000 programmers writing a billion lines of code is to develop simple routines that can be followed and overseen by anyone.
The results won't be as good as mastery, but in many cases they don't need to be. There's a lot of simple software out there which benefits more from being done now than being done right.
Having said all that, I do think rigidity is becoming a problem for the software industry. It's not being employed at the levels needed to make software work, it's being employed at the levels needed to make development legible. Adding procedures that worsen development but make it easier to watch is a serious issue.
https://www.joelonsoftware.com/2001/01/18/big-macs-vs-the-na...
The worst of this group often become indispensable, because they've designed something nobody else can understand. It's politically difficult to push back on this sort of problem, which is why I am job hunting now. Of the six or so really smart guys that remain on my current project, I trust maybe three of them, but would only work with two again (the third is so happy to be here that he doesn't resist any of the chaos)
Software is a team sport. All of my decisions affect how long it takes for you to fix a simple bug. All of yours affect how often I have to stay late to fix a production issue.
I think these things become a religion because there is a large group of developers who simply won't do something unless management makes a rule about it. So now to get them to participate, dogma has to be involved.
In general these are the same folks who attribute all adversity to bad luck instead of lack of forethought. They won't see the consequences of their shortcuts because that's just the way things are.
At that point, you're basically in permanent damage limitation mode anyway, though.
Software development is a skilled and creative activity. Certainly not everyone has to be a "rockstar" or a "ninja" or whatever we're calling those people this week. I've worked with plenty of developers who do a decent, competent job without spending their lives thinking about code 24/7 and staying up to speed on every little development in the industry. However, there is a baseline level of giving a $#!% that is necessary to do a decent, competent job.
I have the feeling that, while TDD is not an absolute, this article doesn't put forward good case examples for skipping it, or at least doesn't try to discuss these examples and find out why they aren't fit. Instead; it takes a shot at stereotypes and builds a strawman on it.
Moderation comes from practice, in fact. It comes from trying and failing, not from extra-prodding the experts, or from studying the matter. And should one be confronted with a zealot, their experimental rebuttal should be convincing enough that zealotry isn't a problem.
On the other hand, OP's assertion that, e.g. a pseudo random generator shouldn't be tested comes without explanations, and frankly is unconvincing : there are acceptance tests (they may not be enough, but passing them is the least you can do) https://en.wikipedia.org/wiki/Randomness_tests, and you can also split the seed and the function you implement, and test thoroughly that the function performs what the algorithm describes.
Likewise, I would totally accept that someone that writes zero tests but has an inexpensive and permanently available source of validation (e.g. from prod) practices TDD.
I'm not sure how you can do validation without writing tests, but let's clarify our terms. I work in the embedded field. We rarely, if ever, write unit tests in the typical sense. Most tests are based on black box testing of the system (related to integration tests) sometimes of a system component if we can plugin a simulator of other components (closest we get to unit tests). Most often, these tests are not written in the same language as the system or even running on the same platform. They talk over serial or something to the device and record the responses back.
These tests still have to be written, even if it's just:
Send messages X, Y, Z
Receive messages A, B, C as responses
A, B, C should match *data* modulo time tag
A test has been written. And if this testing is run frequently against the code changes, and failures treated typically as blockers on working on other features or issues, then this is definitely TDD. Often, however, these tests are run infrequently, ergo not TDD, despite the comprehensiveness of the test suite. The tests do not drive the development (though perhaps they should more often than not).