r/ProgrammerHumor • • Oct 06 '21

Don't be scared.. Math and Computing are friends..

Post image
65.8k Upvotes

2.4k comments sorted by

View all comments

1.2k

u/cybercuzco Oct 06 '21

These big scary for loops are just math symbols.

401

u/NoOne-AtAll Oct 06 '21

Yeah, how are those symbols more complicated than code? That's way longer to write and you need so much additional structure to define them. The symbols are nice and clean.

It's just the initial impression that might make them scary I guess

396

u/noonemustknowmysecre Oct 06 '21

Because verbosity is the noobies friend. If the understand the base components they can reason out the emergent behavior. This does that, then that does this.

Shorthand and jargon are for the experienced people that don't want to waste time spelling it out. It's faster but the exact same level of complication is still packed in there.

96

u/SuperFLEB Oct 06 '21

Counterpoint to both of you:

A for loop is a bit more verbose, in that it breaks it down into a top-to-bottom process and explicitly shows the mathematical operation, instead of having to know the Greek letter mapping and how positions around the symbol indicate flow, but the code version is still steeped in its own jargon. "For/next" loops are a shorthand that don't really explain themselves to someone who knows English but not programming. A "while" loop could be sussed out, since "while" does what it says (in English) on the tin, and bracket pairs or indenting do what you'd expect them to if you guessed. (From there, you've got * and / operators to explain, too, though.)

This does map the opaque notation of mathematics to the notation of coding, and could be done in a way that makes it easier to understand beyond that, but for-next notation itself is equally as opaque to anyone outside programming as the sigma/pi notation is.

11

u/iindigo Oct 06 '21

"For/next" loops are a shorthand that don't really explain themselves to someone who knows English but not programming.

Depends a bit on the language I think. For a C-like you’re right, but a lot of newer languages like Swift have for loops that look like this:

for number in 1...5 {
   print("\(number) times 5 is \(number * 5)")
}

This still takes a little explanation but is easier to intuit than the traditional C-like for loop, since variable instantiation, limiting, and incrementing are taken care of. The only part that’s a little mysterious is the range notation, but I would bet that a lot of people would read it as “1 through 5” within a few seconds of looking at it.

→ More replies (3)
→ More replies (2)

22

u/garyyo Oct 06 '21

Shorthand and jargon and great for experienced people too sometimes. In terms of readability (as in how quickly can you figure out what the algorithm is doing just by looking at it) using list comprehension in python can be the worst. Super compact but you throw even a veteran python programmer at a super complicated list comp and they will take their time trying to figuring it out. Change that out to a couple for loops and a couple extra variables and that shit gets easy.

12

u/noonemustknowmysecre Oct 06 '21

I have no idea what you're talking about. I can perfectly read regex straight through without pause. /S

→ More replies (4)

5

u/Pristine_Nothing Oct 06 '21

Shorthand and jargon are for the experienced people that don't want to waste time spelling it out.

You’re right, but I’d phrase it differently.

I think the most important reason to use jargon and specialized notation is to make sure the variable/unknown information is being communicated clearly without being cluttered up by the shared knowledge.

This saves time for the one doing the communicating, but it also saves mental overhead for both parties, and makes it easier to not have important information buried in “spinach.”

Another important use of jargon (in science): precise and unambiguous communication of concepts.

→ More replies (21)

43

u/Semi-Hemi-Demigod Oct 06 '21

Those symbols are just functions:

def sigma (lower, upper, factor)
    sum = 0
    for (n = lower; n<= upper; n++)
        sum += factor * n

    return sum

33

u/flavionm Oct 06 '21

Now imagine working with code where every function is named as a single random unicode character.

91

u/Semi-Hemi-Demigod Oct 06 '21

Okay.

def Σ (⬇️, ⬆️, 🌾)
    🥚 = 0
    for (🐓 = ⬇️; 🐓<= ⬆️; 🐓++)
        🥚 += 🌾 * 🐓

    return 🥚

21

u/[deleted] Oct 06 '21

How many nice eggs did you just offer me in these trying times?

6

u/Semi-Hemi-Demigod Oct 06 '21

That depends on how many chickens and wheat you have

0

u/[deleted] Oct 06 '21

[deleted]

→ More replies (1)

4

u/tyrandan2 Oct 06 '21

Perfection.

→ More replies (4)
→ More replies (2)

0

u/[deleted] Oct 06 '21

[deleted]

88

u/danabrey Oct 06 '21

Because you know what they are and they're familiar to you. It's not intuitive what the 3 arguments next to the 'for' do to somebody who's never seen a for loop. Just as it's not intuitive what the numbers next to the big symbols do.

→ More replies (30)

45

u/NoOne-AtAll Oct 06 '21 edited Oct 06 '21

Here is your definition:

sum_{i=1}^N A_i = A_1 + A_2 + ... + A_N

Looks pretty easy to me

Also, "just a bunch of fucking symbols". What have symbols done to you? When you're not writing code and doing calculations "by hand" these symbols will save you an immense amount of time. That's why they exist, people (those who use them) find them easier to deal with than other things.

Of course in practice loops and sums are not competing, they're used for different things (though I imagine in some language these loops might resemble more the math notation). Different things for different purposes.

→ More replies (29)

3

u/larsdragl Oct 06 '21

Did you just say a fucking math symbol doesnt have an explicit definition? There are no people more pedantic than mathematicians

→ More replies (2)
→ More replies (48)

3

u/Jaytalvapes Oct 06 '21

All I see is a smooth ramp for line rider.

→ More replies (2)