Live data from Hacker News

Think in Math, Write in Code

justinmeiners.github.io

221–230 of 256 posts

Re: Think in Math, Write in Code

#221
post #8

There's an unpopular and somewhat seemingly contradictory opinion that I have regarding this, because this isn't the first time I've seen this topic brought up. Mathematics and programming are not really all that related to each other and I think there's an overemphasis on the importance of math in programming for 99% of applications. Sure, mathematical thinking can be useful, but it's only one type of logical thinki…

Mathematics and programming are not really all that related to each other and I think there's an overemphasis on the importance of math in programming for 99% of applications.

I think if you regard logic (in philosophy) and maths (as a huge broad field) and computing (specifically a sub-field in maths to some people) its pretty clear that logic and computing have a huge relationship.

I can think of lots of other subfields in maths, which have huge inter-relationships. Applied maths, whats that got to do with probability? Well.. it turns out that modelling complex systems uses Monte-Carlo methods .. (a fictional example, I suspect, I know the manhattan project people dreamed MC up but its modern applicability is unknown to me)

You don't think maths informs programming, or its over-stated? I guess thats true, in as much as poetry doesn't inform legal writing. But, I observe that people who do enough poetry or writing to understand the difference between a simile and a metaphor and an allegory, are really on-point communicators, and the law needs that concision and precision.

I think people with good groundings in maths (and logic) make awesome programmers but its not strictly neccessary to be a mathematician to know how to "speak" in a programming language. What pitfalls you avoid from your knowledge, I cannot say. But I do know that huge pitfalls lie in naieve programming: large loops iterating over un-initialized data structures, not understanding the if-then-else logic or side effects of expressions, tail recursion..

I think computing is a sub-field in maths. How much it matters depends on how much your code matters.

Re: Think in Math, Write in Code

#223
> As you read this example, I think your tendency may be to think that its statements are obvious.

Not to me. The statements suffer from a common math problem: using single letters. if the names were better, maybe they would be obvious. But instead I have to keep back referencing former definitions to remember what they were.

I have to do something similar with p(1) and p(2) - I need to make sure my memory is correct on which data is in which place. If you could reference them in a more obvious way that would help.

I also have to make an assumption from the very start - what "t" refers to is only obvious in definition 3, when it was used in definitions 1 & 2.

It's ironic that the article recommends thinking in math and writing in code when they have thought in math and written in math.

Re: Think in Math, Write in Code

#224
post #71
post #8

There's an unpopular and somewhat seemingly contradictory opinion that I have regarding this, because this isn't the first time I've seen this topic brought up. Mathematics and programming are not really all that related to each other and I think there's an overemphasis on the importance of math in programming for 99% of applications. Sure, mathematical thinking can be useful, but it's only one type of logical thinki…

I've been thinking about this quite a bit, but coming from a different angle. I've been helping at my kid's school with coding clubs for primary students. When teachers are recruiting for the coding club they always mention the students who are good at math as good candidates. But what I have noticed is that the students who do the best in coding are more often musically inclined or linguistically talented. It seems…

A friend of mine taught high school math until recently. He told me a similar thing about math. The kids who are "good at math" in elementary school don't necessarily become the top math students later on. He felt that his best math students were the ones who were just curious about a lot of things as kids.

Re: Think in Math, Write in Code

#225
I'm not employed as a programmer, so I'm somewhat detached from the business. I've noticed that the programmers and other kinds of engineers tend to split off into two different camps. There are "qualitative" engineers who are good at arranging and organizing things, and fitting things together. There are "quantitative" engineers, who solve problems through the application of math and science principles.

A small difference along one of these directions amplifies itself over time, as problems are assigned based on aptitudes and interests, resulting in a growing division. And I don't know if there's a consistent ratio across industries or businesses, but at the shop where I work, it's roughly 90% qualitative, and 10% quantitative. Any problem involving math is brought to the small handful of "math people." They end up being busy enough with just that kind of work and nothing else. If a project runs into a math problem, it grinds to a halt until one of the math people can spare some attention.

Likewise, the qualitative folks are perpetually busy too. Nobody is short of work because of gaps in their abilities. So I think it's quite fair to say that a programmer can do without math, if they find the right niche, but a programming project might need one or two math people from time to time.

Re: Think in Math, Write in Code

#226

Earlier quoted context omitted.

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 so…

>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-consumi…

[deleted]

Re: Think in Math, Write in Code

#227
post #159

Earlier quoted context omitted.

Logic is part of math, not the other way around. Basically the same goes for your "how it affects the web" since that becomes about directed graphs. On algorithms and data structures: do you actually evaluate their complexity if that's not about math? Math is everywhere.

I'm always mindful of complexity when designing algorithms but I would barely consider it math. It's not an exact science and you're hardly quantifying anything. Complexities are essentially just eyeballed approximations.

I would like to welcome you to the formal study of complexity: https://complexityzoo.uwaterloo.ca/Complexity_Zoo

Re: Think in Math, Write in Code

#228
I might be misunderstanding here, but this sounds like it might lead to too much up front design, which is a trap I'm naturally inclined to fall into. Again maybe I'm misunderstanding. I found the example pretty opaque (granted I gave up trying to understand it very quickly).

I do think starting with basic architecture and design is a good idea, but it's important to jump in and test your assumptions before you become too attached to them. In my mind the ideal flow goes something like this:

1. Short design/modeling/architecture/etc session

2. Test assumptions by hacking together a quick prototype

3. Revamp design.

4. Implement more robust prototype.

5. Iterate as necessary.

Re: Think in Math, Write in Code

#229
post #201

I must have some deep-rooted, maybe repressed, anger towards maths. I can program just fine, write functions left and right, receive data, do something with it, return a result... But in maths? Oh dear god no I couldn't write a math function on a piece of paper to save my life. Someone recently pointed out the parallels and while I couldn't deny it, as it was plain as day... I never once considered it during all thes…

The most common intersection, IMO, is inductive reasoning. If you can write a working recursive function, you are also writing an inductive proof. The only explanation I have for why people think there's either no link to math, or that they can program but can't do math, is a cultural sledgehammer smashed into our collective skulls while we're young that tells us we can't.

This is a shame, because we spend a lot of effort in deliberately avoiding common abstractions in case it scares programmers away, but really we're just making it harder for everyone to learn all these things. We either eventually recognise the underlying pattern through our brain's capacity to extrapolate from examples (hard, slow), or learn the pattern explicitly and recognise it, or often never learn the pattern and have to learn each new language's way of doing things one by one.

And of course when we either don't know or deliberately avoid effective abstractions we make or propagate mistakes. See Java's first crack at Future, for example, which was practically useless since the only thing you could do with a Future was wait for it to be the present.

Re: Think in Math, Write in Code

#230
post #208

Earlier quoted context omitted.

Author here. I would say that modeling the computational process in math is not typically helpful (you already have a formal programming language) you should model the real-world (or at least computer world) problem you are trying to solve. Carefully define operations and constraints, introduce abstractions for solving them, etc. Do you have an example of an I/O problem you have thought about that you would like me t…

Thanks for the article and discussion that sprang up around it! The question I'm trying to ask is how I should express (part of) programs on paper using math when I don't see how they are related to math. Example: How could I easily express a function that takes a string as input and outputs the string capitalized using math notation? I understand that the problem you solve in the post should probably be put on paper…

This is a great question. What I really tried to emphasize in the article is that math is not a formal language. Since its just you and coworkers, write out the parts you need as you need them, and ignore details. After all, its an exercise to help you think.

If I needed uppercase I would just say:

  `up(s)` is a function that maps a string s to its uppercase string
Writing that down, you and I already have a pretty good idea of how it works, or its included in our libraries, and we can figure out the details when writing the code.

This is of course assuming `uppercase` is a minor part of another algorithm. If it was the subject of discussion I might describe it like this:

  Let `u(c)` be a function that maps a characters to its uppercase character. In ASCII `u(c) = c + K` where K is some offset.

  To capitalize an entire string we need to apply that function to each character.

  Let `up(s)` = (u(c_1), u(c_2), ... u(c_n))
  where the string s = (c_1, c_2, ... c_n)
Perhaps that helps, but I don't think it addresses your question directly. I think you need some experience reading math to know how to describe problems, but I don't think you need to know fancy math. A knowledge of functions, sets, tuples, logic, summations, etc, will get most of what you need.

I highly recommend that book I linked in the article: "Introduction to Graph Theory" By: Trudeau

Post reply on HN