15 ms·
Why not program right?
- csours 8y agohttps://web.archive.org/web/20180705200232/https://bertrandmeyer.com/2018/05/24/not-program-right/ https://web.archive.org/web/20180705200232/https://bertrandm...
- csours 8y agoI guess my default answer is: because I have to solve some business problem to get paid, and I never have enough information or time to do it right - or phrased differently: If I took enough time to do it right, someone else would have already done it wrong and moved on. Is there a "better" answer than worse is better?
- cosarara 8y agoWell I don't know if it's a "better" answer, but in my case, I didn't know about Eiffel. I had heard the name, nothing else. Maybe I'll try writing something with it now.
- lkrubner 8y agoBetter is generally better than worse is better. The passive nature of worse is better postpones problems till later on. The philosophy of "worse is better" works for those who are competing mostly on price, but are you sure you want to spend your career in that category? That can be a tough life, ground down by low cost bids. Among the consultants I've known in New York, the better one's definitely avoid the "worse is better" philosophy. I'm talking about those consultants who charge in the range of $200 to $400 an hour. These people are hired to implement a "best is best" approach. I'm working on a project like that now, where we brought in one of the best AWS consultants in this region to build out a complex infrastructure, following best practices. We are pleased to see something take shape that we know is very good. Consultants of this type can not afford to be passive, because they are being paid, in part, to push pass obstacles, including political obstacles, and implement an architecture as close to idea as possible.
- pierrebai 8y agoThe problems with that position and how your phrased it are that it is wrong, sounds condescending, is an easy way out and more importantly, completely ignores the real issue. And the real issue is time vs result. That's the essence of worse is better. It's the well documented fact of diminishing return and exponential cost of additional quality. You can deliver N features over a given fixed time. Given the urve of quality vs time, there is a true sweet spot where your maximize value, for whatever criteria you want for the value. Spending too much time on fewer items or too few time on too many will respectively waste time on unnecessary polish and deliver stoo many items of no value. There is a sweet spot.
- pdimitar 8y ago> There is a sweet spot. There is, but it definitely is NOT at one of the extreme ends of the curve where experienced bean-counters will negotiate down the engineering effort (and thus money) to the absolutely minimum necessary for the project not to implode 2 days after release. Truth is, at one point in your career you have to start pushing back against those bean-counters. They will never get tired, and they are everywhere. At certain point you take a stand, put your foot down and say: "No, this will NOT be done in 2 days. It will be done in 5 and thus it won't have to be patched 10 times in the space of a week. If you don't like it, my resignation is ready." You would be surprised how often that works. Many of the business types and managers are bullies only because nobody ever fought back. ...Or you could take a more diplomatic, but still firm, stance. Like "the overall cost of this feature will be much lower if I work on this for 5 days instead of 2". But IMO that almost never flies so I became blunt with time and I simply don't care. I passed five job offers lately for similar reasons and I couldn't be happier about it.
- dustingetz 8y agoI've done consulting at that rate. There is selection bias in what you describe: the kind of client who will pay that rate tends to already know they want "best is better" which is why they hired the fancy consultant in the first place. I have also consulted at that rate to pre-revenue startups, a much harder sales pitch because you're literally decimating their burn. The pitch here is advancing their business to the next stage as fast as possible. For this, worse is absolutely better as they don't yet even know what "best" is. They do however know what "done, delivered your MVP in two days" is. BTW if any of you want your MVP delivered in two days, consulting portfolio is in profile.
- endymi0n 8y agoYes. The fundamental weakness of the OPs view is that there are different types of „right“ depending on the correct tradeoffs to make. My main guide for that tradeoff is estimating how often code will be read vs. written vs. executed. All those combined plus the time it takes to do code and testing make up the total time to optimize. That way, I‘ll write exploratory code different than a prototype, which again is different to a protoduction test, a small production system I‘ll maintain myself, a large production system with different teams and software I‘ll completely hand over or open source as a library. Only an experienced engineer will realize that each of those versions of the same functionality will be „right“ in the context of their creation.
- jjaredsimpson 8y agoWorse is better could be described as "easiest sufficient approximation." But if I have a business problem with a small enough epsilon you might not get sufficiently close with your worse techniques in a reasonable amount of time. And to stretch the metaphor even more you may hit an asymphtote and never supply a solution. Doing something "right" isn't necessarily always slower. Sometimes it is the only path to an acceptable solution.
- coldtea 8y ago>I guess my default answer is: because I have to solve some business problem to get paid, and I never have enough information or time to do it right That's a red herring. People working on a business program don't need to encode the "whole information to do it right" (e.g. for the eventual version of the program when every constraint is known). Just the ones that have to hold at the time they right it, and they already know those -- from their current requirements. >or phrased differently: If I took enough time to do it right, someone else would have already done it wrong and moved on. That's also a red herring, unless you don't write tests either.
- TooBrokeToBeg 8y ago> unless you don't write tests either. You mean "oracles" (from the blog post). Just program correctly amirite? eyeroll If your example doesn't deal with user input, you're talking about a problem of modeling under known conditions, which is trivial and ivory tower arrogance.
- coldtea 8y ago>You mean "oracles" (from the blog post). Just program correctly amirite? eyeroll I don't see the reason for the eyeroll. You'd have a point if the "just program correctly" meant "just get it right". But it's not. It's "just use contracts and invariants explicitly defined in your program, Eiffel style to check its correctness". Which is even more powerful than writing tests. >f your example doesn't deal with user input, you're talking about a problem of modeling under known conditions, which is trivial and ivory tower arrogance. Not sure how tests are anything other than "modeling under known conditions". Are the assertions in your test in any way "unknown"? If you mean fuzzing, you can do that trivially with Eiffel style programs as well. And the "tests" you do that way are there in the code, available in the debugger, and so on.
- pdimitar 8y agoCan you give a practical example on how to encode invariants explicitly in a more popular language? As for contracts, basically 99% of the languages have some form of the Java interfaces, or Elixir behaviours/protocols, or LISP's several ways of doing it. But for invariants, I would appreciate an example if you are willing to provide one.
- junke 8y agoMy problem with the slogan is that it has become a catch phrase for those who either haven't read the original article, or have read it and either have forgotten what it really talked about or never understood it in the first place. As a catch phrase, it is often used to justify shoddy design, or following the crowd rather than doing what is right, or as short-hand for the real claim that our customers are too stupid to either appreciate or deserve high quality products. Why spend the time doing things right, this line of reasoning goes, when we all know that worse is better. You are far better off giving the customer something that you know is less than what you could produce, because they (those simple customers) will think that it is better. Worse is Worse (Jim Waldo) https://www.artima.com/weblogs/viewpost.jsp?thread=24807 https://www.artima.com/weblogs/viewpost.jsp?thread=24807
- mmt 8y agoThat's just a summary of an interpretation of the original (a copy of which he links to): https://www.jwz.org/doc/worse-is-better.html https://www.jwz.org/doc/worse-is-better.html (Be sure to copy-paste to avoid jwz's HN referer-trap) This line also appears just before that paragraph: > Of course, worse is better is a much catchier slogan than better depends on your goodness metric Ultimately, this seems to be applicable even to this discussion, where one goodness metric is "correctness" and another goodness metric is "expediency". In the original essay, it's simplicity of implementation rather than expediency, but I'm not sure that's all that huge a conceptual difference here (other than for the purposes of a slippery slope argument).
- pmoriarty 8y agoWorse is better doesn't sound so bad for just a single (small) project. Where it starts to go badly off the rails is when there's a company culture of worse is better and one quickfix, bandaid solution is piled on top of another. They then wind up with one or more Leaning Towers of Pisa made up of bandaids, hacks, and quick fixes, and everyone running around like headless chickens putting out fires and trying to bandaid all the failures as the towers are constantly in the process of collapsing. This leads to an ever widening spiral of hacks upon hacks upon hacks as company culture, lack of manpower, and pennypinching never gives them the luxry of doing it right, and cutting the gordian knot by scrapping everything and doing it right from the start becomes ever more impractical.
- LandR 8y agoThis is a depressingly accurate description of my life :(
- gowld 8y agoThe whole web is "worse is better". You can say "worse is worse", but that implies you think the web is worse than something that.. what, would have sprung into existence if the current web was suppressed?
- icebraining 8y agoProject Xanadu?
- ryrobes 8y agoSadly - this is virtually ALL companies over size X, age Y. The dirty "silos" outnumber the clean by far.
- dimman 8y agoI think the phrase you’re looking for is: good enough.
- icebraining 8y agoI find contracts interesting, but it seems to me that they're only useful for transformations that are easier to check than to implement, no?
- deleted 8y ago[deleted]
- ben509 8y ago> This is where I stop understanding how the rest of the world can work at all. Without some rigorous tools I just do not see how one can get such things right. Well, sure, spend weeks of trying out test cases, printing out the structures, manually check everything (in the testing world this is known as writing lots of “oracles”), try at great pains to find out the reason for wrong results, guess what program change will fix the problem, and start again. Stop when things look OK. When, as Tony Hoare once wrote, there are no obvious errors left. Most businesses put their data in a DBMS, so you have integrity constraints "to ensure database consistency with the business rules or, in other words, faithful representation of the conceptual model of reality."[4] The relational model is both complete and a lot easier to understand than using the predicate calculus directly. The other shortcoming of any language's invariants is that it lives in your source repo. As coders, we often forget that your production data represents contracts with customers, and you have to take account of the real data when migrating your business rules. That's why the M is in DBMS. More directly answering the question, most languages can employ property tests [1][2][3] that, very closely to how Eiffel does it, allow you to specify the precise invariant and validate it under randomly generated tests. But, honestly, a great deal of code, even math heavy code, doesn't have nice general invariants. Real functions dealing with business logic and bugs are piecewise and messy. And then that only covers the handful of functionality that is even remotely expressible in mathematical form. You still have the user interface to deal with, dependency management, your entire deployment story, and all the problem extant between chair and keyboard. Technology can't substitute for the grunt work of testing, testing, actually using your system and talking to your customers. [1]: https://hackage.haskell.org/package/QuickCheck https://hackage.haskell.org/package/QuickCheck [2]: https://hypothesis.readthedocs.io/en/latest/ https://hypothesis.readthedocs.io/en/latest/ [3]: https://github.com/HypothesisWorks/hypothesis-java https://github.com/HypothesisWorks/hypothesis-java [4]: http://www.dbdebunk.com/2017/06/what-meaning-means-business-rules_11.html http://www.dbdebunk.com/2017/06/what-meaning-means-business-...
- macintux 8y ago> But, honestly, a great deal of code, even math heavy code, doesn't have nice general invariants. Real functions dealing with business logic and bugs are piecewise and messy. At the edges, the invariants are going to be messy, but it would seem like this gives you ample excuse to define functions with strong, narrow invariants as the core of your application, with input transformation functions at the edges.
- nlawalker 8y agoI find that a lot of folks only think of programming in terms of variables and executable instructions that modify them. The notion of an invariant is not part of their toolbox, and the exercise of modeling a domain is not something they really engage in: if the program doesn't do what they want it to do, either the instructions are wrong, or there need to be more of them to handle the cases that aren't currently handled.
- vbtemp 8y agoI think this is correct. It's understandable when it's a physicist or electrical engineer trying to code something up to get something working. What really upsets me is when it's professional software developers who never evolve out of that mindset. I feel like at the end of the day the trick is to think algebraically -- Your data types and structures are some domain and you define operations over the elements of that domain in such a way that certain properties hold.
- candiodari 8y agoThe big advantage of CS is the accessibility of the domain. You cannot take that away and hope nothing else changes. That, of course, means any idiot or 8 year old can just pick it up and run with it. They may become less of an idiot after a while, but this may not be desirable or expedient, and it's great that that's not much of a problem. I mean, this is a bit like saying, why doesn't every physicist do everything by just coming up with a random differential equation for their problem then use fixed points to deduce the long-form non-recursive version and isolate out the wanted variables into long form ? It's, after all, usually by far the simpler process, especially since everyone can come up with a few differentials for any situation. Coming up with the correct long form directly, however, is absurdly hard. So if you simply learn to work with differentials, that's the way to approach essentially any problem. With a tiny caveat ... "learn to work with them" is 6 months of study and intensive practice, and that's assuming you already know a lot of math that isn't exactly high school level either, including a significant list of "tricks" that you just need to know by hard. But what you can do with it is amazing. But the level of knowledge and understanding required is just too high for anything resembling general application.
- carapace 8y ago"The future is here, it's just not evenly distributed yet." ~W. Gibson We are like lumberjacks who so love our axes that we refuse to even consider chainsaws. Many of us don't even know they exist, or if we do, think of them as esoteric and nearly magical. And then there's the fellow who says, "I'm too busy chopping down trees to learn use a chainsaw. I've got to get these trees chopped today!" (So learn to use a chainsaw on the weekends maybe? They really aren't that hard.)
- pdimitar 8y agoI agree with you, however the chainsaws in your example are definitely hard as hell... consensus algorithms, net splits -- and you already have much more a single programmer could handle (most of us anyway).
- syastrov 8y agoI have heard of property based testing (e.g. QuickCheck). Is the main innovation of Eiffel that the author is referring to that these invariants are written alongside the actual code AND are configurably checked at runtime? Because ordinarily, you might sprinkle assertions throughout your code, but these are checked only at the point you add them, rather than between statements as I assume Eiffel does. In that case, I see some benefits in the form of documenting logical assumptions which are actually validation when code is run (also during manual testing). I could imagine this being implemented in other languages by hooking into statement execution much like a profiler or debugger and executing the checks. Does anyone know of such tools for other languages, e.g Python or JS? Does anyone have real-world experience with this development technique on an actual project in production?
- mpweiher 8y ago> ...and examine the evidence. And the evidence is that people write working, even reliable software without Eiffel.
- jacquesm 8y agoWell, yes. But they do that by replicating a lot of functionality that might as well be pushed down a level. Because every program with output that people or other systems rely on needs that level of reliability and yet only very few provide it to a degree that the company behind it would accept liability if it doesn't. Usually 'working' and 'reliable' get redefined to 'working with what we've tested it with' and 'reliable insofar as our statistics indicate'. Without knowing for sure that you've really covered all your edge cases you're a typo away from some disaster. Fortunately most software isn't that important. But for software that is that important these strategies, even if imposed from the outside rather than embedded in the language will pay off.
- mpweiher 8y agoOh, I am not saying there are no problems. And I don't deny a certain emotional appeal to having safety features provided by the language. However, great (quality) is delivered with those kinds of features and without, and crap software is delivered with those kinds of features and without. And more importantly, I have seen little to no evidence that having those sorts of features actually substantially changes the statistical distribution of crap/quality software, no matter what we feel should be the case. People can use these safety features or not, and they can use them well or not. Just like they can use non-linguistic safety mechanism, such as really good test-suites...or not. Elsewhere, he writes: > This is where I stop understanding how the rest of the world can work at all. And so you probably need to upgrade your understanding. If the world doesn't conform to your understanding of it, the thing that's lacking is almost certainly your understanding of the world. Because it does work.
- jacquesm 8y ago> And more importantly, I have seen little to no evidence that having those sorts of features actually substantially changes the statistical distribution of crap/quality software, no matter what we feel should be the case. I have. Our company has done a fairly large number of studies on the internals of companies producing software and the better companies are at the tech the better they do in the long run. Note that there is such a thing as 'good enough', and once that bar is cleared I'm fine with cutting a corner here or there to meet a deadline. But I'm not fine with categorically ignoring quality and security in favor of short term wins.
- Animats 8y agoI wish we had tools for proving object invariants widely available. But such tools tend to come from people pushing their latest type theory or functional programming or something. They're too complex and abstract for most programmers. I tried to fix this once, but it was too soon in the early 1980s.[1] (That was before objects. We would have had object invariants if objects had existed back then. We had function invariants and module invariants.) This stuff is useful is when you have lots of modifiable data structures which need to be consistent. Window managers. Operating systems. Game engines. Database internals. Most of the things you need to prove are trivial. But you need tools to check that invariant A is maintained by code far distant from where invariant A is defined. Maintenance programmers will miss that. [1] http://www.animats.com/papers/verifier/verifiermanual.pdf http://www.animats.com/papers/verifier/verifiermanual.pdf
- gowld 8y agoIs there a viable solution that isn't type theory or functional programming or something? If it were feasible to do so, wouldn't we see progress in "everyday" common language?
- Animats 8y agoThere was for Modula III. DEC SRL in Palo Alto did a nice verification system for Modula III. But Modula III went down with Digital Equipment Corporation. C/C++ has too much undefined behavior. Ada died off. The scripting languages don't need it as much. Rust had potential for proof work, but went off in a different direction. There are modern proof systems, but they're rarely integrated with the programming language.
- ainar-g 8y agoI thought the legacy of Modula-3 lives in OpenJML (through ESC/Modula-3 -> ESC/Java -> ESC/Java2 -> OpenJML)? I have never heard anyone use it though.
- nickpsecurity 8y ago"Ada died off. " On the verification side, it's never had more users that I'm aware of. SPARK and Frama-C are very active compared to almost non-existent use of formal methods in industry decades ago. Rust could similarly have a subset integrated with Why3 platform to make the formal methods easier to use. Further, I've seen extraction done from Coq to C and Rust. There's also one person modeling C in WhyML to write the algorithms in the latter but extract to former. Or something like that. Could be done for Rust, too.
- AnimalMuppet 8y ago> The only way to achieve demonstrable correctness is to rely on mathematical proofs performed mechanically. This is guaranteed to fail. What are you going to prove by your mathematical proof performed mechanically? That the program performs correctly? How do you define "correctly"? At bottom, it is defined by an informal specification in peoples' heads. You cannot mathematically prove correspondence to that, even in principle. At best, you can prove correspondence to the most-high-level formal specification. But how do you prove that that specification is "what the program should do"? The next problem with this approach is that it has costs. Having to write a mathematically rigorous formal specification for all the behaviors of a program takes non-trivial time and effort. As others have said, that effort could have been put into other things, like more features. Would we rather have more perfect software, or more feature-rich software? Above a certain level of quality, we'd rather have more features. (Yes, software often drops below that level of quality...)
- tathougies 8y agoYou can prove performance properties, memory properties, and formal properties, or any combination of the above. The question of 'what the program should do' is not a mathematical one; it's a philosophical one in the most general sense, and most likely a business one.
- PaulAJ 8y agoI was an Eiffel fanboy in the early 90s, when the only alternatives were Smalltalk and C++. It was obvious to me that garbage collection was necessary for modular systems, and that Eiffel assertions were the sweet spot in formal specification: lightweight enough to be usable in the real world, but formal enough to let you state and demonstrate useful things about your code. However I was still always bothered by mutation. Everything was fine as long as you didn't change any data structures, but as soon as you added mutation to the mix everything fell apart. You could state an invariant, but if you shared a reference to an internal structure then you had to trust everything else in the system not to change anything. Then I discovered functional programming in the shape of Haskell. Its still not perfect, but it's fundamentally better than OO.
- webreac 8y agoI have also learned eiffel and read Meyer's book. The terrible standard library with the deep inheritence trees was my main complaint about this language. All his critics about C++ were very insightful. At that time almost nobody was speaking about immutability (GRAAL was called a language without variable). Java was almost revolutionary with its immutable strings.
- Cobord 8y agoLooks like algebraic query language AQL. Anyone familiar with both this and AQL who can give the comparison?
- tchaffee 8y agoI used to love these kinds of articles three decades ago. Then you get a programming job with budgets and deadlines and even stupid decisions based on politics and you hate all that at first until through experience you realize that even poorly engineered cars can get product from point a to point b and do so all over the world. Free markets eventually only have time for perfect solutions. And a perfect solution according to markets is the solution that does the job for the lowest cost over time. For a website that will support a two week marketing campaign, you don't need anything talked about in this article. In fact the only responsible decision is to ignore this type of approach and just build the damn thing with someone that has a track record. And then throw it out and move on. Based on empirical evidence, there isn't really a problem at all with the way people program. Markets have already mostly figured out the rare cases when such robustness is really needed. And it's rare. The only "right" way to program is to take as many stakeholder requirements into consideration as possible. And those requirements are rarely around program correctness. So this article is good (although I think you're really looking at functional programming by this time in history) but first make sure a top priority is program correctness before getting into the mode suggested by the article. One final stakeholder requirement that's always a priority: you have to be able to find qualified developers, and what developers learn is based on popularity and fashion. It's a real world constraint even if it's distasteful to the idealist and well intentioned types who write these articles.
- kbenson 8y ago> And a perfect solution according to markets is the solution that does the job for the lowest cost over time. Yep. If we actually valued correctness, the market would place some cost on incorrectness. Security is a common example of this. If we wanted, we could punish software developers or publishers for shipping security bugs (for example, making them liable), and then we would see an immediate shift in how software was written. That's not necessarily an endorsement of that position (it lacks enough nuance to even be remotely considered a good idea), it's just a fairly illustrative example.
- blub 8y agoThe market can't solve solve the quality problem, that's a fantasy. Sw quality is so poor across the board that there is almost no one producing high quality, reliable software. My bloody phone can't properly select text in this box for example. Sw companies have optimised their production for decades to develop software that's just good enough to ensure profit and they've trained customers to expect and accept poor quality. Is anyone surprised when Windows reboots for updates in the middle of an important presentation? No, that's how Windows works. Companies will even reduce quality to improve profits and still get away with it if the customers don't notice, don't understand or are too apathetic to take action. Often there is no action to take that will sufficiently punish the offending company. Security is a great example: it's been bad for so long that core pieces of technology are fundamentally insecure and can't be significantly improved without total rewrites. Punishing developers and companies would result in a collapse of commercial software development, so humanity collectively accepts that software is by nature insecure.
- Kenji 8y agoI usually hear the reverse question: people ask us, the Eiffel community, to explain why we program our way. I went to this man's lectures and I can assure you, yes, I do ask why they're still programming in Eiffel. The IDE is horribly broken and the binary that is generated is at least an order of magnitude slower than anything written in C#, Java or C++. Often, things wouldn't compile and you just had to clean build to get it to work, even for very small projects. Never in my life have I seen such a verbose and slow language and such a broken IDE. I'll take any language over Eiffel.
- RcouF1uZ4gsC 8y agoContracts were just recently voted into C++20 (https://herbsutter.com/2018/07/02/trip-report-summer-iso-c-standards-meeting-rapperswil/ https://herbsutter.com/2018/07/02/trip-report-summer-iso-c-s...) With the addition of contracts, C++ will natively support this style of programming without ASSERT macros.
- InclinedPlane 8y agoWhy not? Because provably correct software is not necessarily correct software. One of the biggest classes of defects in programs is missing details in specifications, and provable correctness against the wrong specification doesn't help with that problem at all. Provable correctness is one technique in software development, it's not the only technique nor even the most important technique nor even a required technique.
- mpweiher 8y agoYep. Provable correctness can be useful iff you have a formal specification, and iff that formal specification is more likely to be a correct reflection of the requirements than the code + some tests. While there are times when that's the case, those are rare.
- mhd 8y agoOne thing I'd really like to see is a debate between Meyer and his predecessor Niklaus Wirth. The latter was definitely willing to sacrifice some correctness if that means making the system easier to implement and learn. Just compare Oberon and Eiffel, or, heck, "Algorithms and Data Structures" and "Object-Oriented Software Construction".
- i_don_t_know 8y agoI'm not sure Wirth has ever sacrificed correctness. He has been willing to sacrifice performance though, that is, if a simpler solution was fast enough he went with that (e.g. linked list instead of hash table for symbol lookup in a compiler). He's also not been afraid to question established wisdom and practice if it lead to simpler implementations (e.g. the file API in Oberon). I suspect Wirth would not object to codifying pre/post-conditions and invariants per se. But I think he would object to using them as a band-aid around complicated implementations. It's hard to convince yourself that your implementation is correct when the pre/post-conditions and invariants are themselves complicated and hard to understand.
- tzs 8y agoOT: what is the definition of a "root" of a multigraph? In a regular graph, the most common definition I've seen is that a node is a root iff you can reach every other node starting from it. In the graph in the article, that is true both of nodes 1 and 2, but he says 1 is the only root.
- subjectsigma 8y agoYes, I get he thinks his language is the best, and maybe it really is. Constraint-based programming sounds cool. Then again, so does logic-based programming, but I'd wager most people have never written a single line of Prolog, and for good reason. It's hard and slow to write, and to run for that matter. Maybe his language would be more popular if he wasn't such a snob about it.
- rthille 8y agoIf I had to develop software like that, I'd quit and dig ditches for a living.