Think in Math. Write in Code

(jmeiners.com)

35 points | by alabhyajindal 4 days ago ago

13 comments

  • lxe 16 minutes ago

    I think the author makes a good point about understanding structure over symbol manipulation, but there's a slippery slope here that bothers me.

    In practice, I find it much more productive to start with a computational solution - write the algorithm, make it work, understand the procedure. Then, if there's elegant mathematical structure hiding in there, it reveals itself naturally. You optimize where it matters.

    The problem is math purists will look at this approach and dismiss it as "inelegant" or "brute force" thinking. But that's backwards. A closed-form solution you've memorized but don't deeply understand is worse than an iterative algorithm you've built from scratch and can reason about clearly.

    Most real problems have perfectly good computational solutions. The computational perspective often forces you to think through edge cases, termination conditions, and the actual mechanics of what's happening - which builds genuine intuition. The "elegant" closed-form solution often obscures that structure.

    I'm not against finding mathematical elegance. I'm against the cultural bias that treats computation as second-class thinking. Start with what works. Optimize when the structure becomes obvious. That's how you actually solve problems.

    • orforforof a few seconds ago

      I really enjoyed the book Mathematica by David Bessis, who writes about his creative process as a mathematician. He makes a case that formal math is usually the last step to refine/optimize an idea, not the starting point as is often assumed. His point is to push against the cultural idea that math == symbols. Sounds similar to some of what you're describing.

  • sfpotter an hour ago

    I agree with the thrust of the article but my conclusion is slightly different.

    In my experience the issue is sometimes that Step 1 doesn't even take place in a clear cut way. A lot of what I see is:

      1. Design algorithms and data structures
      2. Implement and test them
    
    Or even:

      1. Program algorithms and data structures
      2. Implement and test them
    
    Or even:

      1. Implement
      2. Test
    
    Or even:

      1. Test
      2. Implement
    
    :-(

    IMO, this last popular approach gets things completely backwards. It assumes there is no need to think about the problem before hand, to identify it, to spend any amount of time thinking about what needs to happen on a computer for that problem to be solved... you just write down some observable behaviors and begin reactively trying to implement them. Huge waste of time.

    The point also about "C-style languages being more appealing" is well taken. It's not so much about the language in particular. If you are able to sit down and clearly articulate what you're trying to do, understand the design tradeoffs, which algorithms and data structures are available, which need to be invented... you could do it in assembly if it was necessary, it's just a matter of how much time and energy you're willing to spend. The goal becomes clear and you just go there.

    I have an extensive mathematical background and find this training invaluable. On the other hand, I rarely need to go so far as carefully putting down theorems and definitions to understand what I'm doing. Most of this happens subliminally somewhere in my mind during the design phase. But there's no doubt that without this training I'd be much worse at my job.

    • taeric 4 minutes ago

      Reminds me of the attempt to TDD a way to a sudoku solver. Agreed that it is a bit of a crazy path.

      Not that Implement/Test can't work. As frustrating as it is, "just do something" works far better than many alternatives. In particular, with enough places doing it, somebody may succeed.

  • zkmon 40 minutes ago

    That's still a chaotic composition of thoughts, not driven by any identified structure or symmetry of the situation.

    Why a program is needed? What constraints lead to the existence of that need? Why didn't human interactions need a program or thinking in math? Why do computers use 0s and 1s? You need to start there and systematically derive other concepts, that are tightly linked and have a purpose driven by the pre-existing context.

  • almostgotcaught an hour ago

    what compels software people to write opinion pieces. like you don't see bakers, mechanics, dentists, accountants writing things like this...

    Edit: to everyone responding that there are trade mags - yes SWE has those too (they're called developer conferences). In both categories, someone has to invite you to speak. I'm asking what compels Joe Shmoe SWE to pontificate on things they haven't been asked by anyone to pontificate on.

    • WorldMaker a minute ago

      Mathematicians certainly write volumes of opinion pieces. The article you are complaining about starts from the presumption that software could benefit from more mathematical thinking, even if that doesn't explain broader general trends.

      (But I think it does apply more generally. We refer to it as Computer Science, it is often a branch of Mathematics both historically and today with some Universities still considering it a part of their Math department. Some of the industry's biggest role models/luminaries often considered themselves mathematicians first or second, such as Turing, Church, Dijkstra, Knuth, and more.)

    • lxe 17 minutes ago

      > you don't see bakers, mechanics, dentists, accountants writing things like this...

      There are literally industry publications full of these.

    • SatvikBeri 44 minutes ago

      Accountants certainly do. They've had trade magazines with opinion pieces since well before the internet.

    • pissmeself an hour ago

      bakers and mechanics have not had their ego stroked by being overpaid for a decade.

    • 1-more 24 minutes ago

      If they'd had opinion pages at the time, the inventors of nixtamalization would have and should have written something like this.

      • tickerticker 4 minutes ago

        LOL. Have not seen the "nixta" word since 10 years ago when i was researching how to make grits.

    • exe34 15 minutes ago

      Bakers certainly write books and magazines[0] on baking, as well as interminable stories about their childhood. Mechanics: [1]. I could only find one obvious one for dentists: [2]. Somebody else did accountants in the thread. I think it's a human thing, to want to share our opinions, whether or not they are well supported by evidence. I suspect software people write blogs because the tech is easier for them given their day job.

      [0] https://www.google.com/search?q=blaking+magazine [1] https://www.google.com/search?q=mechanics+magazines [2] https://dentistry.co.uk/dentistry-magazine-january-2023-digi...