golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.18k stars 17.56k forks source link

proposal: Go 2: #56522

Closed WhipMe closed 1 year ago

WhipMe commented 1 year ago

Author background

Related proposals

Proposal

Costs

WhipMe commented 1 year ago

Dear Golang Management and Developers, I am a legacy programmer (C, Pascal, Visual Basic, FoxPro, Delphi), and this is a first time that I have reached out to consider other programming languages. Golang seems to be the right fit for me at the moment. I did find learning this language irksome in some respects, because many of the typical programming conventions which we take for granted seemed to be broken.

For the most part, I really like many of the differences of Golang from C: Golang seems to deal with the problems of programming tedium, especially over repetitive minor and superfluous tasks, handling errors, trawling through data sets, string and number base handling, code management, encryption, and command line issues - it is a very, very good and welcomed change.

However, I have quickly noticed that there is a "severe" handicap which is limiting the flexibility - the casual use, of the scope of the Golang language. And, I am very surprised that none of you have noticed it for such a long time, but, a handicap it is! It may be debatable on how "severe" it is, but that lack, that pertinent restriction which is causing this issue to such a beautiful language and a potentially even more powerful one is the following problem:

There is no "While" loop!

I will chide you over something so trivial - and yet so important as this, because it is something that you as experienced programmers, should have not have allowed to escape or to get away from you. So, why is the While loop so important, and a critical key to opening the full power of the Golang language? Well, I will state it as follows:

If you look at most other languages, you will notice that as a rule they all provide various types of loop statements, so that various issues of intense programming processing can be dealt with.

The "While" loop provides an answer to programming issues to do with data processing, where the conditions for processing some types of information cannot be restricted to how many times a process can happen. In other words, a While loop is vital, where the processing, or the state of any particular algorithm, is not dependent on numbers, but on whether the condition of a variable, or a state of a process or object is valid - invalid, or true or false. How could you not see this?

Yes, Golang is an "exceptionally potent language", but if you are going to reinvent "C/C++" surely you are not going to want to take a significant step backwards? - But this is what you did! So, Golang excels in everything that "C" fails, but yet it still has an anchor around it's foot. - Where is our While loop?

So, the proposed constituents of the Golang while loop could be as follows:

while{

}()

Where the conditions that can be put in the argument side (brackets) of the loop can be Boolean (true or false); Iterative as with a For loop; Or conditional, on the state of any particular Object or Class. For example:

while{ ... }([(a)!=nil][!true][(a ==) false][err<>""][a++ < max])

Also, having a While loop makes code and code management more readable: This is because of loop nesting. For example we could have a need to put two loops - one inside the other: A While loop inside For loop, so that we have,

for _, range:= []a{ while{ ... }(c != true) }

So, as you know, any number of Switch or If/Else statements, etc., can be nested in the body of this loop, but the power of using a While loop should now become very clear. In that the "discrimination" of different tasks can be conveniently handled, so that a For loop can be used for particular purposes, and a While loop for handling others. So, before you criticise me, this is still my first day in learning and using Golang.

while{ ... }(fmt.Scanln(&var) <> err)

...or,

while{ ... }(rtnval() == "")

Therefore, in conclusion, do you see how the flow of the language, the new and more flexible possibililites the language has, when the While loop is made available? It means that programming structures, processing, logic states and forks are more methodical and better organised. And, it means that specific "state" requirements, can be made, kept and maintained, without the overhead and problems with only having a For loop.

David

zephyrtronium commented 1 year ago

The for keyword denotes three different kinds of loops, including the traditional while loop: https://go.dev/tour/flowcontrol/3

WhipMe commented 1 year ago

...It could be argued that one size fits them all. However, the Golang For loop is tantamount to a "straight-jacket", because it does not appreciate that some logic arguments and expressions are not process intensive, but should only be fired by a change in logic or a "state".

For example:

while{ ... }(rtnval(aStr) == "")

So, the processing part of the code "waits", until a specific condition is met. That criteria could be from any form of input, or a change in any object or function, so that the limitations of program execution is not process or process intensive or time related.

ianlancetaylor commented 1 year ago

@WhipMe The loop you describe doesn't exist in C either. Are you saying that Go does not have a do while loop? That is true, but there are no plans to add one.