1

Topic: Arithmetics of constants in language Go

Authors of language considered that with rules of coercion of types for numbers in language of Si there are big problems. It seemed to them that one of vital issues in Si are the errors connected to misuse of arithmetical operators for numbers of different types. As a result they invented something: https://blog.golang.org/constants the Essence that for constants one rules, and for variables others operate. It leads to following effects: var a =-1; fmt. Println (uint32 (a));//OK const b =-1; fmt. Println (uint32 (b)); constant-1 overflows uint32 Why for overflow variables it is authorized, and for constants is not present? (Because in one case at the moment of compilation it is possible to check up, and in other is not present. Seriously?) Or such: var a = 9223372036854775296 + 1.0; const b = 9223372036854775296 + 1.0; fmt. Println (uint64 (a), "", uint64 (b));//9223372036854775808 9223372036854775297 It is comparable from a C ++: auto a = 9223372036854775296 + 1.0; constexpr auto b = 9223372036854775296 + 1.0; std:: cout <<uint64_t (a) <<"" <<uint64_t (b);//such approach seems to 9223372036854775808 9223372036854775808 Me illogical in the absence of uniformity in rules of calculation of variables and constants. In the approach With ++ it is necessary to understand as coercion of types and arithmetics works.  expressions a calculation method does not influence. In Go, as well as in any other language with  numbers, from necessity of understanding of arithmetics to leave it does not turn out, but unlike With ++, it is necessary to remember different rules for constants and variables. Looks so that wanted to secure programmers against "difficult" rules of arithmetics of numbers, and as a result only all complicated and made less convenient. It not that area of programming in which it is necessary to try to simplify something. Apparent complexity of arithmetics of numbers is unremovable. It is impossible to write the qualitative code, without knowing and without thinking of it. What think of it?

2

Re: Arithmetics of constants in language Go

Hello, Ale, you wrote: Well, in a C too the full uniformity is not present. The integer constant has type, minimum from this, in what it gets (in the standard the order - signed int, unsigned int, signed long, unsigned long is defined...; for oct/hex both are tried signed/unsigned, for decimal - only one). Other question that there do not cut conversion for constants, absolutely normally to transfer-1 in unsigned in spite of the fact that the C does not guarantee branching code usage. A> authors of language considered that with rules of coercion of types for numbers in language of Si there are big problems. It seemed to them that one of vital issues in Si are the errors connected to misuse of arithmetical operators for numbers of different types. As a result they invented something: https://blog.golang.org/constants the Essence that for constants one rules, and for variables others operate. A> it leads to following effects: A> A> var a =-1; A> fmt. Println (uint32 (a));//OK A> const b =-1; A> fmt. Println (uint32 (b)); constant-1 overflows uint32 A> A> Why for overflow variables it is authorized, and for constants is not present? (Because in one case at the moment of compilation it is possible to check up, and in other is not present. Seriously?) It just yet does not make problems - at least while the code is not generated by the automatic machine (and Go generally has the strongest hindrance to it, for example, compilation errors on not used import or a variable, therefore on such it is impossible to calculate). A> Or such: A> A> var a = 9223372036854775296 + 1.0; A> const b = 9223372036854775296 + 1.0; A> fmt. Println (uint64 (a), "", uint64 (b));//9223372036854775808 9223372036854775297 A> And here it already diversion. If they enter strict typification with the prohibition of direct conversion between numerical types both an and b should not be compiled at all, and the more so in different directions of conversion. A problem in it, instead of in that, a constant or not. A> It is comparable from a C ++: A> A> auto a = 9223372036854775296 + 1.0; A> constexpr auto b = 9223372036854775296 + 1.0; A> std:: cout <<uint64_t (a) <<"" <<uint64_t (b); //9223372036854775808 9223372036854775808 A> Because in a C at autoconversion buoyant types it is more important whole, and implicit conversion is resolved. A> such approach seems to me illogical in the absence of uniformity in rules of calculation of variables and constants. In the approach With ++ it is necessary to understand as coercion of types and arithmetics works.  expressions a calculation method does not influence. In Go, as well as in any other language with  numbers, from necessity of understanding of arithmetics to leave it does not turn out, but unlike With ++, it is necessary to remember different rules for constants and variables. Yes A> Looks so that wanted to secure programmers against "difficult" rules of arithmetics of numbers, and as a result only all complicated and made less convenient. It not that area of programming in which it is necessary to try to simplify something. Apparent complexity of arithmetics of numbers is unremovable. It is impossible to write the qualitative code, without knowing and without thinking of it. Go generally represents in this plan itself a wild compound of the advanced decisions and the most wild obscurantism. Sharpening on branching code for negative and fixed sizes of types - ok, not it the first (Java, C#, Javascript...) ; Generally, I would tell that as other platforms are not present and long will not be, it can be put default. The requirement of explicit conversion between numerical types - in plus (when it  is required - by an example above, here a rough defect). Compulsoriness of arithmetics with  (remain low N bit) - basically too on favor (especially, for example, in comparison with such the Author:  Date: 18.06.14; though I categorically would prefer more floppy syntactic regulation), but at least it was necessary in standard library to add control function (type such). Trifles, but tasty, type "bit shifts do not truncate width of shift till width of a word" (though too would be desirable to see in library the optimized machine operations for which to provide adequate width - a problem of the programmer). And generally, group of situations where the C speaks about undefined behavior or implementation defined, received the unambiguous decision. On the other hand, an antiquity and nonsenses the Most stupid rules "not used variable, import => a compilation error" (autogeneration went wood) the Failure from exceptions and  export Rating under the register of the first character Absence private in classes Syntactic roughnesses of type "in import is necessary inverted commas on a packet, and in package - are not present" absolutely stupid antiquities of type of a prefix 0 for octal constants Mistakes in operation with channels the Strange logic of concept "new type, same, as old" ( it is impossible to enter; in Ada it solved explicit new in type X is new Y) At compilation - a failure from standard  and "a sunset manually" with the  and the optimizer, certainly more feeble, than  like LLVM (in spite of the fact that  the interface code to OS anywhere does not disappear). Invariable sharpening GC on a minimum of time delays though not all it is necessary for tasks. It is possible to continue. Together with deranged "charisma" of authors it leads to that speak to all critics "it is not pleasant - a suitcase, station, Java" (or other language to substitute to taste), and in users - to formation of club of fanatics instead of sober users (for example, on DOU such two already  all).

3

Re: Arithmetics of constants in language Go

Hello, netch80, you wrote: N> Invariable sharpening GC on a minimum of time delays though not all it is necessary for tasks. And here what not so? Nish  it is small web services where it is important to answer quickly, thus overall performance is less important, since if the server does not consult, it should be scaled simply. It is clear that is good, if there is heap GC for all occasions as in Java, but it costs money, generally. Or in the language there are any decisions which do not allow to do others GC? Problem Go (and some other technologies like React) that is bits from intrigues of corporations which they throw out in audience. Abruptly, it is better to have in itself it, the not to have, the  open-sors, but upon it is had bits and a heap pottering about  around which try to collect from these bits something made. If to compare with Java or.NET then all on the contrary, in itself key and the same MS though uses these technologies.NET NET, but hides nothing and  all all in the same way as for itself, the Visual Studio which distributes to all remaining and  uses the same. I.e. for MS sale.NET is an important part of business, and for Google it is simply internal tool which for the certain reasons opened, but if suddenly decide to close, to incomes Google it generally does not affect in any way. Accordingly it is necessary or to use these technologies, in that case when they well approach under your case (or you are so abrupt that you can finish them), or simply to use those technologies which creators approach to all to it more responsibly. For now Go forms in Google and its overall objective - to service specific interests of Google, the priority will be given to that is important for Google. And if for Google  are not important, they there will not be.

4

Re: Arithmetics of constants in language Go

Hello, netch80, you wrote: N> At compilation - a failure from standard  and "a sunset manually" with the  and the optimizer, certainly more feeble, than  like LLVM At them one of the major purposes - speed of compilation, for the sake of it are ready to go on foolish grammar and  optimization. And LLVM brake as a reptile.

5

Re: Arithmetics of constants in language Go

Hello, vsb, you wrote: N>> Invariable sharpening GC on a minimum of time delays though not all it is necessary for tasks. vsb> And here what not so? Nish  it is small web services where it is important to answer quickly, thus overall performance is less important, since if the server does not consult, it should be scaled simply. If they aim on pauses to 100 microsecond, it already in any way web services. It is level which comes nearer to small HFT. vsb> it is clear that is good, if there is heap GC for all occasions as in Java, but it costs money, generally. Or in the language there are any decisions which do not allow to do others GC? Like there are no such. Generally, stop the world it is possible to make with any language. vsb> problem Go (and some other technologies like React) that is bits from intrigues of corporations which they throw out in audience. Long thought, than to object, but did not find. We will consider valid. vsb> For now Go forms in Google and its overall objective - to service specific interests of Google, the priority will be given to that is important for Google. And if for Google  are not important, they there will not be. Similar on that. They and in a C ++ do not resolve an exception.

6

Re: Arithmetics of constants in language Go

Hello, D. Mon, you wrote: N>> * At compilation - a failure from standard  and "a sunset manually" with the  and the optimizer, certainly more feeble, than  like LLVM DM> At them one of the major purposes - speed of compilation, for the sake of it are ready to go on foolish grammar and  optimization. With optimization still it somehow agree, but at what here grammar? On grammar of brakes now generally it is not enough. C brakes ++ follow the account multimeter ,  and the subsequent optimization to the reasonable code. Remaining  languages very quickly understand. DM> and LLVM brake as a reptile. On optimization, likely. Parcers quite comprehensible on speed, as for normal tasks of such language.

7

Re: Arithmetics of constants in language Go

Hello, netch80, you wrote: N> With optimization still it somehow agree, but at what here grammar? Go it is very easy , of it specially cared. Not only for speed, it still  simplifies, but also for speed too. And at the first acquaintance to language it is well felt - grammar did first of all for the machine, for simplicity of the compiler, in the second only for people.