News for hackers. Stuff that matters.
Re:Think in Math, Write in Code by LandR on Thursday July 18, 2019 @06:06AM (#20468314)
> Is this really a common thing? How can you try to implement something without first having had thought of the solution?

Unfortunately, it's incredibly common.

The result is always almost a mess. Functions that are never called, parameters that are never used, as they discovered their mistake as they were coding but then never went and cleaned up the stuff they don't use anymore. Broken logic, poor performance. Functions with a mess of loops and if statements, nested like 10 indents deep.

You can tell by looking at code if they were making it up as they were going versus implementing a solution they had thought through before starting coding. It's painfully obvious.

When you try to solve your problem by coding, I think you are forced to take a myopic view of only subsets of your solutions and it's near impossible to step back at this point and come up with a nicer, more abstract and probably more concise solution. The solution comes out spikey.

Re:Think in Math, Write in Code by rowanG077 on Thursday July 18, 2019 @06:16AM (#20468364)
Really? I think the best way to solve a problem is to code it. I can never see all the corner cases and logical inconsistencies before I start typing. I have tried to formally model software before I start writing it and in the end it was largely a waste of time because real understanding of the problem comes with coding the solution.

Of course when doing it like this you write a lot of code which later is unused or bad. But I think that will always happen and it's just a matter of having the discipline to continuously clean up after yourself.

Re:Think in Math, Write in Code by braythwayt on Thursday July 18, 2019 @06:25AM (#20468396)
Writing a lot of code you later discard because it isn’t part of the final solution is like throwing clay on the table and then carving away the bits that don’t fit.

Nobody criticizes the sculptor for the clay that ends up on the floor, and clay is heavy. We carve away bits, they have no mass and don’t need to be swept up, all we have to do is cut them away, revealing the final program.

Re:Think in Math, Write in Code by sidlls on Thursday July 18, 2019 @08:48AM (#20469182)
On the other hand the sculptor has considered the type of clay, the quantity, the tools she'd need to use to carve away those bits, and understands enough about what she wants to create to know what bits to carve away first.

Programming may not be (all) math, but it's not art, either.

Re:Think in Math, Write in Code by hutzlibu on Thursday July 18, 2019 @10:11AM (#20469938)
"Programming may not be (all) math, but it's not art, either."

Huh? Maybe the kind of common 8-5 office programming around buisness logic is not, but to design any bigger project is definitely art.

Re:Think in Math, Write in Code by seanmcdirmid on Thursday July 18, 2019 @12:13PM (#20471299)
Math can be considered an art, though not a fine art. Programming by either extension is an art (though again, not a fine art).

https://en.m.wikipedia.org/wiki/Mathematics_and_art

Re:Think in Math, Write in Code by j88439h84 on Thursday July 18, 2019 @01:18PM (#20471949)
I don't see why it couldn't be a fine art.
Re:Think in Math, Write in Code by seanmcdirmid on Thursday July 18, 2019 @01:40PM (#20472170)
Perhaps it could be practiced as part of a fine art, but like carpentry, programming itself isn’t.
Re:Think in Math, Write in Code by thaumasiotes on Thursday July 18, 2019 @02:58PM (#20472915)
> Writing a lot of code you later discard because it isn’t part of the final solution is like throwing clay on the table and then carving away the bits that don’t fit.

How do you make a statue of an elephant?

Re:Think in Math, Write in Code by Gravityloss on Thursday July 18, 2019 @06:50AM (#20468503)
Planning for realistic levels of waste. Throwing away prototypes. Gradually making changes. Keeping backwards compatibility. Testing. Accommodating users with large collective investment in learning.
Re:Think in Math, Write in Code by mannykannot on Thursday July 18, 2019 @08:38AM (#20469109)
This is not a useful analogy; it is more of an excuse for not trying to think things through. Would this be a reasonable analogy for building a bridge?

If you don't have a reasonably detailed idea of what you want and how to achieve it, you are unlikely to get it.

https://dilbert.com/strip/1991-9-6

Re:Think in Math, Write in Code by zbentley on Thursday July 18, 2019 @09:30AM (#20469552)
> Would this be a reasonable analogy for building a bridge?

That is also a useless analogy. Do bridge builders get to test and re-test their bridges in the real, non-simulated world? Can they instantly make a copy of their bridge with a few critical differences and see how the two behave? Can they re-build their bridge in minutes?

Metaphors aside, I think history is ample evidence that "coding your way around a problem" rather than conceptualizing a solution first is a perfectly valid way to approach professional programming. It's not the only way, and it has drawbacks which others have pointed out here. So does the conceptualize-first approach: you might solve the wrong problem, make something inelastic in the face of changing requirements, or fall into the psychological trap of being attached to your mental model even when it turns out that you really didn't think of everything and have to make changes on the fly.

I'm really tired of people being dogmatic about either approach ("move fast and break things/pivot; anyone else isn't really interested in getting stuff done!", "you're just a messy code monkey unless you can hold the solution in your head before you start!"). It's almost always veiled arrogance rather than honest improvement-seeking, in my experience.

Re:Think in Math, Write in Code by mannykannot on Thursday July 18, 2019 @09:56AM (#20469790)
Well, yes, it is a useless analogy... Oh, you meant to say that comparing bridge-building to software development would be a useless analogy? It's not an analogy I made - the point is that just because you can make a cute analogy, it doesn't mean it offers any insight.

> I'm really tired of people being dogmatic about either approach

Exactly - and the implication that I am being dogmatic is a straw man. I am simply opposed to arguments that depend on poor analogies.

Furthermore, all of the bad things that you say can happen if you try to think ahead are as least as likely to happen if you don't, and especially if you have gone in the wrong direction for some time (I know the latter is a manifestation of the sunk-cost fallacy, but it happens a lot on real projects.)

Re:Think in Math, Write in Code by rowanG077 on Thursday July 18, 2019 @09:26AM (#20469500)
Building software is not even remotely the same thing as building a bridge. It would be more akin to the architect creating the drawings twice for the bridge. Once as an exploratory version and the second one the production version.

Oh wait that is actually how architects work. In fact at my work we have multiple CAD designers(not architects though) and it's not uncommon for them to completely throw away a design and start over. I think code should be mostly the same.

Re:Think in Math, Write in Code by 0x445442 on Thursday July 18, 2019 @09:56AM (#20469793)
I'll bet the engineering process of the software written for the Apollo 11 lunar lander was much closer to the bridge building process than you might think. I'll also bet there's a whole host of software projects which use similar processes today. It's just that most of us writing DB skins for "The Enterprise" are rarely, if ever exposed to real engineering for the simple fact that quality software is expensive and typically, our organically grown solutions are good enough.
Re:Think in Math, Write in Code by nwallin on Thursday July 18, 2019 @01:35PM (#20472131)
> I'll bet the engineering process of the software written for the Apollo 11 lunar lander was much closer to the bridge building process than you might think.

Of course, but the Apollo 11 lunar lander was created without the aid of ubiquitous desktop computers. I imagine the SpaceX guidance/control software was written in a way that less resembles bridge-building/Apollo 11 lunar landers and more like the organic processes we see elsewhere in the software industry.

If Neo were to build a bridge in the Matrix, chances are his processes would bear little resemblance to those of the Army Corp of Engineers.

Re:Think in Math, Write in Code by 0x445442 on Thursday July 18, 2019 @10:59PM (#20475857)
> I imagine the SpaceX guidance/control software was written in a way that less resembles bridge-building/Apollo 11 lunar landers and more like the organic processes we see elsewhere in the software industry.

For the guidance/control systems, I bet you're wrong.

Re:Think in Math, Write in Code by ryandrake on Thursday July 18, 2019 @10:36AM (#20470229)
Maybe if we treated the practice of software development more like bridge building, we would have better reliability, fewer outages, fewer zero-day exploits, fewer patches and bugfixes--software that actually works the first time, and every time for years.
Re:Think in Math, Write in Code by Jtsummers on Thursday July 18, 2019 @10:41AM (#20470294)
I work in aviation/defense. They try to treat it just like building bridges, and it's a disaster. Please don't.

Software is a design practice/process. Not a building process. Any analogy should be to the design phase of other engineering disciplines.

Re:Think in Math, Write in Code by mannykannot on Thursday July 18, 2019 @10:00AM (#20469833)
Your designers are working with abstract models. They are thinking about problems at a conceptual model, they are not putting up structures and seeing if they work.
Re:Think in Math, Write in Code by rowanG077 on Thursday July 18, 2019 @10:08AM (#20469903)
code is also an abstract model.

The CAD designers absolutely test if things work. Why do you think almost every engineering bureau has 3D printers.

Re:Think in Math, Write in Code by mannykannot on Thursday July 18, 2019 @10:18AM (#20470010)
> Code is also an abstract model.

Sure, but it is not the only one. You are allowed to think at other levels, and it can be quite useful, especially on larger systems.

Re:Think in Math, Write in Code by drdeca on Thursday July 18, 2019 @09:26AM (#20469504)
In the analogy with the clay, I believe they are both adding and removing clay
Re:Think in Math, Write in Code by mannykannot on Thursday July 18, 2019 @06:33AM (#20468433)
Really? yes, it is very common.

The problem of this approach is that it does not scale to large systems. If you don't spend much time on thinking in the abstract about how it will work and what might go wrong, then, by the time you have written enough code to find that out, you may have gone a long way down the wrong path, and not all architectural-level mistakes and oversights can be patched over.

No-one does this perfectly -- even people using formal methods will overlook things -- but, on a big project, if you don't put much effort into thinking ahead about how it should work, and try to identify the problems before you have coded them, you are likely to end up where, in fact, many projects do find themselves: with something that is nominally close to completion but very far from working. Those that are not canceled end up looking like legacy code even when brand new.

Re:Think in Math, Write in Code by rowanG077 on Thursday July 18, 2019 @07:41AM (#20468735)
If you want to have low quality solutions that kinda work on the first try then sure go for it. Your approach will inevitably lead to insurmountable technical debt that can't be paid off.

Big projects should be cut into smaller pieces where each piece can be relatively easily rewritten.

Re:Think in Math, Write in Code by mannykannot on Thursday July 18, 2019 @08:14AM (#20468947)
> Big projects should be cut into smaller pieces where each piece can be relatively easy rewritten.

To come up with the right smaller pieces, you have to think about how they will work together to achieve the big picture. That means interfaces and their contracts, and if you get them wrong, you end up with pieces that don't fit together, and do not, collectively, get the job done.

Big problems cannot be effectively solved in a bottom-up manner, and perhaps the most pervasive fallacy in software development today is the notion that the principle of modularity means you only have to think about code in small pieces.

Re:Think in Math, Write in Code by rowanG077 on Thursday July 18, 2019 @09:34AM (#20469588)
That's my point you CANNOT possibly come up with the right smaller pieces until you have a solution that you have verified works.

What do you think other engineering principles do? They create a proof of concept. Verify it works and then create the real thing. That is why "real" engineering companies have hundreds of tools to test stuff.

I really don't understand why people want software to be different. You write some shitty throwaway web app then sure go ahead and don't prototype anything just hire a "software architect" that designs something and use that.

But do you want something that actually works then that is completely useless. Prototype, verify, start over if necessary. That is the way to write quality software.

Re:Think in Math, Write in Code by mannykannot on Thursday July 18, 2019 @10:13AM (#20469953)
>That's my point you CANNOT possibly come up with the right smaller pieces until you have a solution that you have verified works.

That's beside the point. The point is that coding is not the only way to verification, especially at the architectural level.

> I really don't understand why people want software to be different.

It seems to be you who wants to be different. Making prototypes is expensive and time-consuming, so engineers try to look ahead to anticipate problems. Prototyping in software is cheaper, but not so cheap (especially at the architectural level) that thinking ahead isn't beneficial.

Re:Think in Math, Write in Code by slx26 on Thursday July 18, 2019 @03:28PM (#20473147)
in my opinion the big difference and problem is that space and resources are virtually unlimited, and a "product" can keep changing indefinitely too. and if something fails, in most cases it will fail very differently than in other engineering disciplines. I agree it would be great to write more prototypes and all that, but hey, capitalism: good_enough/shitty makes money, so that's where we are (also, CS is rather new, we are still figuring out a lot of things, still getting deep in the mess)
Re:Think in Math, Write in Code by gaze on Thursday July 18, 2019 @10:15AM (#20469970)
I have found that the gap in understanding between thinking you understand something and implementing something as a program is often much smaller than the gap between having programmed something and having proven it.
Re:Think in Math, Write in Code by rowanG077 on Thursday July 18, 2019 @11:10AM (#20470618)
What do you mean having proven it? As in you tested it and it works or do you mean you have formally using math that your solutions always gives the correct result?

If it's the former then this is part of building it. An implementation without proper testing is incomplete. If it's the later I actually agree. Only the most sensitive of applications require that level of sophistication though.

Re:Think in Math, Write in Code by gaze on Thursday July 18, 2019 @11:17AM (#20470697)
A mathematical proof or analytical solution. I understand that analytical solutions only apply for very narrow ranges of problems but... consider writing an analytical solution to a differential equation versus applying a numerical solver. A numerical solution rarely leads to as deep an understanding as an analytical solution or a number of approximations in various limits. I feel like we're in the limit of something analogous to writing numerical solvers and claiming understanding from observing the output.
Re:Think in Math, Write in Code by ben509 on Thursday July 18, 2019 @02:43PM (#20472800)
I often take the compromise technique: write a prototype and build off that.

The prototype is generally a mess, but I throw that out anyway.

Re:Think in Math, Write in Code by 0x445442 on Thursday July 18, 2019 @09:47AM (#20469696)
Welcome to "Agile".
Re:Think in Math, Write in Code by nineteen999 on Friday July 19, 2019 @12:21AM (#20476151)
Rhymes with "fragile".
Re:Think in Math, Write in Code by mruts on Thursday July 18, 2019 @07:12AM (#20468583)
I’ve always thought that you don’t really understand a problem until you have a solution to it. What I like to do is first write a naive solution to a problem so I can understand it better. Then I throw away the code and start again. I invariably learn a lot more about a problem and the most elegant solution than I would have if I had just tried to write a perfect solution right off the bat.

Code, after all, is cheap (and often totally worthless). More developers should adopt this view. I’ve seen engineers more times than I would care to admit get attached to some piece of code, as if it was some piece of themselves. Code is more akin to dogshit than the limb of a dog.

Re:Think in Math, Write in Code by TeMPOraL on Thursday July 18, 2019 @07:23AM (#20468643)
The problems we're solving when building software happen simultaneously at different levels. Some are best solved by prototyping. Others are best solved on a whiteboard. The trick is correctly identifying the problems, and then knowing which layer they belong to. If you try to code up a prototype for a design problem, you'll most likely waste a lot of time and not reach any useful conclusions in the end (or end up shipping the broken thing). If you try to whiteboard a coding problem, you can get stuck forever drawing things, with no result to show for it.

In my experience, the problem levels go differently than one could naively expect. Data structures, abstractions, module interfaces - all problems dealing directly with code - are best solved first on a whiteboard, where evaluating and iterating through them is cheap and effective. User interfaces, user experience, usefulness of a part of a program - things dealing with business and user needs - are best solved through prototypes, because you can't reasonably think through them on paper, you have to have a working thing to play with.