Live data from Hacker News

Programming as a Way of Thinking

blogs.scientificamerican.com

81–90 of 133 posts

Re: Programming as a Way of Thinking

#81
post #75
post #37

Earlier quoted context omitted.

Naming is hard, no question. Context helps, though. In realm where I live, computer science, x, y, and z likely correspond to something in the problem domain, like "rate" or "time". And even if we're dealing in pure, as opposed to applied, math, you should still be able to come up with names like "surfaceArea" or "interval".

So how would you rename a, b, c, x and y in the quadratic formula? https://en.wikipedia.org/wiki/Quadratic_formula It is impossible to get better than one letter variable names here. This goes for most expressions in maths, to make things simpler we just use one letter variables for everything. This forces us to learn that the names aren't important, all that matters is how the names relate to each other. The problem…

The problem with the quadratic formula is that, without referring back to the polynomial or thinking through the proof, I have no way to know which coefficient corresponds to which term of the polynomial. Here's an improvement on the variable naming:

X and Y are descriptive of an overwhelmingly common abstraction, the cartesian coordinate system. They do about the best job they can do.

The coefficients (a, b, c) are opaque. It seems like they would be better generalized as (C_2, C_1, C_0) (or subscripts instead of _#), to let C_N represent "The coefficient for the x^N term of the polynomial").

A few extra characters that are acceptable to mathematicians (subscripts are ++good) would make the formula much more readable, and lets us generalize to higher-order polynomials for similar solutions (not that they necessarily exist).

Re: Programming as a Way of Thinking

#82
post #75

Earlier quoted context omitted.

So how would you rename a, b, c, x and y in the quadratic formula? https://en.wikipedia.org/wiki/Quadratic_formula It is impossible to get better than one letter variable names here. This goes for most expressions in maths, to make things simpler we just use one letter variables for everything. This forces us to learn that the names aren't important, all that matters is how the names relate to each other. The problem…

The problem with the quadratic formula is that, without referring back to the polynomial or thinking through the proof, I have no way to know which coefficient corresponds to which term of the polynomial. Here's an improvement on the variable naming: X and Y are descriptive of an overwhelmingly common abstraction, the cartesian coordinate system. They do about the best job they can do. The coefficients (a, b, c) are…

By the time you get to math in college (at least past the normal calculus sequence) that's how it typically is done.

  \sum(i = 1, n) a_i * x^i
And other similar conventions.

Re: Programming as a Way of Thinking

#83
post #44

Earlier quoted context omitted.

This article starts to get at an idea that I've had for a while now -- that mathematicians are doing it wrong. And you're making a typical programmer mistake in thinking that. Programming is geared towards having people who are experts in programming, but not in a specific subject area, be able to develop and maintain code. Therefore practices like descriptive variable names help provide context to people who cannot…

True, much of math is relegated to experts. This is _exactly_ the problem. Why do you think so many adults have such little understanding of math and will proudly proclaim that they haven't used algebra or geometry in their adult life? Yes, there are are some areas of mathematics that are extremely specific and do require experts but a lot of math is useful to people in general and anything we do to make it easier fo…

Making mathematics accessible to the general public isn't part of mathematicians' jobs, nor is it something most of them care about.

If you want to write some articles that make mathematics more accessible to the general public, and you want to use longer variable names in order to do that, nobody is going to stop you. It's unreasonable, however, to expect mathematicians to try to do this at the same time they're doing their actual jobs.

Re: Programming as a Way of Thinking

#84
post #59
post #44

Earlier quoted context omitted.

This article starts to get at an idea that I've had for a while now -- that mathematicians are doing it wrong. And you're making a typical programmer mistake in thinking that. Programming is geared towards having people who are experts in programming, but not in a specific subject area, be able to develop and maintain code. Therefore practices like descriptive variable names help provide context to people who cannot…

The perception that math is useful stems from it's use by non experts. As a topic goes from specialists to generalists reusing a tiny set of terms becomes a horrible waste of time. Worse, math becomes less precise when different areas reuse terms like infinity, set, numer, area, etc to mean vastly different things let alone identical notation for different ideas.

> The perception that math is useful stems from it's use by non experts.

You might be surprised by how many mathematicians would disagree with the assertion that "math is useful" (I suspect a majority would at least think such a statement was overly broad).

Re: Programming as a Way of Thinking

#86
post #31
post #28

Earlier quoted context omitted.

If a variable can be literally anything, what would you name it instead of 'a'? 'anything'? Sometimes a variable does not refer to anything specific at all. For example, type variables in Haskell are often denoted using single letters, simply because they can be literally anything, and no sane human wants to type out 'anything' all the time, just so her code can be used as a beginner's intro to the language in questi…

There may be occasions when a single letter makes sense, but this should be the exception, not the rule. If you've got a ton of "anything" variables in your code, then that means there's probably a better, more understandable design for your system which expresses what the variables represent with more precision.

> If you've got a ton of "anything" variables in your code

> design for your system

We're not talking about programming; we're talking about math; that's the whole point.

Re: Programming as a Way of Thinking

#87
post #54

Earlier quoted context omitted.

Interestingly, 500 years ago, math was to your taste. There were not much symbols in it, but lots and lots of English (or, more often, French, German, or Latin) sentences that took paragraphs upon paragraphs of text to describe what today a couple of equations do...

To "explain". I find a good paragraph explaining what the equation means and implies is far more useful than the equation alone. This is all the typical "what" vs "why". If you just want to describe the what then the formula alone might be enough (and just presuming everyone know what the variables mean), but if you actually want to convey a some meaning that formula needs to be explained.

You are arguing against a strawman. I have never seen any piece of mathematics that was just formulas. The heavy majority of any mathematical writing is plain text -- formulas and notation are only used when it would be much less practical to express something in text.

Re: Programming as a Way of Thinking

#88

Earlier quoted context omitted.

>it's hard to find examples of good style of Python programming I've never really bought that this matters so much as long as you just write sensibly in general. How many python users really make sure to do everything a "pythonic" way?

I think, it depends on how you use Python. 1. "Executable pseudocode", almost a toy language to explain few algorithms in your article. 2. Sysadmin tool. Replacement for shell, a way to write quick throwaway scripts. 3. "A modern Lisp". Universal language for implementing AI algorithms, DSLs etc. I, personally, use 3rd variant. I write quite big programs in Python, for example I made few compilers in it. That's why c…

I would posit there are far more methods than these besides. Python is a powerful language that is flexible enough to be used for all these and more. You or anyone will inevitably write code they believe to be best suited to their problem, pythonic or not, weighted by the coder's ability and personal definition of "pythonic"

Re: Programming as a Way of Thinking

#89

Earlier quoted context omitted.

True, much of math is relegated to experts. This is _exactly_ the problem. Why do you think so many adults have such little understanding of math and will proudly proclaim that they haven't used algebra or geometry in their adult life? Yes, there are are some areas of mathematics that are extremely specific and do require experts but a lot of math is useful to people in general and anything we do to make it easier fo…

Making mathematics accessible to the general public isn't part of mathematicians' jobs, nor is it something most of them care about. If you want to write some articles that make mathematics more accessible to the general public, and you want to use longer variable names in order to do that, nobody is going to stop you. It's unreasonable, however, to expect mathematicians to try to do this at the same time they're doi…

Yes, but in addition to bringing in more of the general public it also means you can get up to speed in a new area of the field more quickly.

Re: Programming as a Way of Thinking

#90
post #59

Earlier quoted context omitted.

The perception that math is useful stems from it's use by non experts. As a topic goes from specialists to generalists reusing a tiny set of terms becomes a horrible waste of time. Worse, math becomes less precise when different areas reuse terms like infinity, set, numer, area, etc to mean vastly different things let alone identical notation for different ideas.

> The perception that math is useful stems from it's use by non experts. You might be surprised by how many mathematicians would disagree with the assertion that "math is useful" (I suspect a majority would at least think such a statement was overly broad).

Not really, I chose to stop studying math because what I found interesting was generally really useless, and I find a pointless life's work to be a terrible waste of time.

Worst outcome I recall was being yelled at by a professor for not getting a PHD. ¯\_(ツ)_/¯

Post reply on HN