Live data from Hacker News

C's 'while' is spelled 'for' in Go

tour.golang.org

1–10 of 34 posts

Re: C's 'while' is spelled 'for' in Go

#3

Looking at the syntax (as a Go beginner), I'm not really sure whether that's less or more to learn. Seems like one of those arbitrary language design decisions that don't make a huge difference either way.

Yup. They saved a keyword or two but now you need to count the semicolons to see if there is an increment action.

I don't think it makes a big difference either way.

Re: C's 'while' is spelled 'for' in Go

#4
It's kind of sad that "for" is the keyword programming languages settled on for the loop construct.

Ever since its counterpart "do" was dropped from the for-statement, it's just been utterly nonsensical. I mean how on earth does the word "for" convey a loop?

With the recently designed languages like Go and Swift taking so many cues from the Pascal side of the ALGOL language family, how nobody thought to pick up "repeat" or "loop" is simply beyond me.

Re: C's 'while' is spelled 'for' in Go

#5
post #4

It's kind of sad that "for" is the keyword programming languages settled on for the loop construct. Ever since its counterpart "do" was dropped from the for-statement, it's just been utterly nonsensical. I mean how on earth does the word "for" convey a loop? With the recently designed languages like Go and Swift taking so many cues from the Pascal side of the ALGOL language family, how nobody thought to pick up "repe…

for

Re: C's 'while' is spelled 'for' in Go

#6
post #4

It's kind of sad that "for" is the keyword programming languages settled on for the loop construct. Ever since its counterpart "do" was dropped from the for-statement, it's just been utterly nonsensical. I mean how on earth does the word "for" convey a loop? With the recently designed languages like Go and Swift taking so many cues from the Pascal side of the ALGOL language family, how nobody thought to pick up "repe…

> It's kind of sad that "for" is the keyword programming languages settled on for the loop construct.

Many languages only use `for` to mean a for-each style loop where it reads quite naturally:

Python - `for n in range(1,10)`

Ruby - `for i in 0..10`

Rust - `for n in 1..10` (also picked up the bare `loop`)

Others support for-each style loops along with the less than ideal C-style for loop:

JavaScript - `for (n of [1,2,3])` (second attempt, for-in has too many gotchas.)

Java - `for (int n : {1,2,3})`

Otherwise I agree that `while` reads far more naturally. I guess they must have wanted to minimize the number keywords in Go.

Re: C's 'while' is spelled 'for' in Go

#7
post #4

It's kind of sad that "for" is the keyword programming languages settled on for the loop construct. Ever since its counterpart "do" was dropped from the for-statement, it's just been utterly nonsensical. I mean how on earth does the word "for" convey a loop? With the recently designed languages like Go and Swift taking so many cues from the Pascal side of the ALGOL language family, how nobody thought to pick up "repe…

>I mean how on earth does the word "for" convey a loop?

I don't know about a loop per se, but it's used in plain language when you want the same thing to be done to every element in a set. "Clean this item and put it away. Then do that for every other piece of cooking equipment."

It was actually originally borrowed from its cognate für in German:

>>The name for-loop comes from the English word for, which is used as the keyword in many programming languages to introduce a for-loop. The term in English dates to ALGOL 58 and was popularized in the influential later ALGOL 60; it is the direct translation of the earlier German für, used in Superplan (1949–1951) by Heinz Rutishauser, who also was involved in defining ALGOL 58 and ALGOL 60.

https://en.wikipedia.org/wiki/For_loop

Re: C's 'while' is spelled 'for' in Go

#8
post #7
post #4

It's kind of sad that "for" is the keyword programming languages settled on for the loop construct. Ever since its counterpart "do" was dropped from the for-statement, it's just been utterly nonsensical. I mean how on earth does the word "for" convey a loop? With the recently designed languages like Go and Swift taking so many cues from the Pascal side of the ALGOL language family, how nobody thought to pick up "repe…

>I mean how on earth does the word "for" convey a loop? I don't know about a loop per se, but it's used in plain language when you want the same thing to be done to every element in a set. "Clean this item and put it away. Then do that for every other piece of cooking equipment." It was actually originally borrowed from its cognate für in German: >>The name for-loop comes from the English word for, which is used as t…

> "Clean this item and put it away. Then do that for every other piece of cooking equipment."

Without the "do" it's nonsensical. And that was exactly my point.

Re: C's 'while' is spelled 'for' in Go

#9
post #8
post #7

Earlier quoted context omitted.

>I mean how on earth does the word "for" convey a loop? I don't know about a loop per se, but it's used in plain language when you want the same thing to be done to every element in a set. "Clean this item and put it away. Then do that for every other piece of cooking equipment." It was actually originally borrowed from its cognate für in German: >>The name for-loop comes from the English word for, which is used as t…

> "Clean this item and put it away. Then do that for every other piece of cooking equipment." Without the "do" it's nonsensical. And that was exactly my point.

That was just one way of phrasing it. You could just as easily put it as, "For every piece of cooking equipment, clean it and put it away."

Re: C's 'while' is spelled 'for' in Go

#10
post #8
post #7

Earlier quoted context omitted.

>I mean how on earth does the word "for" convey a loop? I don't know about a loop per se, but it's used in plain language when you want the same thing to be done to every element in a set. "Clean this item and put it away. Then do that for every other piece of cooking equipment." It was actually originally borrowed from its cognate für in German: >>The name for-loop comes from the English word for, which is used as t…

> "Clean this item and put it away. Then do that for every other piece of cooking equipment." Without the "do" it's nonsensical. And that was exactly my point.

I think there's an argument that "do" is just a placeholder for the body of the loop, i.e. "clean this item and put it away". If you flip the order that the body and the iteration are expressed so that it reflects what most programming languages use for syntax, it would be "for each piece of cooking equipment, clean it and put it away". There's no "do" here, nor is it needed.
Post reply on HN