5 ms·
From a C/C++ programmer's POV those may look like GOTO labels, I agree. The proposed syntax is probably a consequence of a modern trend in using := for declarat
by williamvds 4y ago
From a C/C++ programmer's POV those may look like GOTO labels, I agree.
The proposed syntax is probably a consequence of a modern trend in using := for declaration and assignment.
x := 5
Where you can optionally insert the type between the colon and equals, otherwise it is deduced
x : int = 5
- teo_zero 4y agoIn English, the colon is used to separate a term to its definition, so it looks perfectly apt to mark declarations. Besides, it makes it trivial for text editors to implement "go to definition", and many other niceties without a real semantic parser.
- thechao 4y agoI used to code for a language called "Spad" — originally shipped in 1972(?). The syntax: x : t = e Was called "headform" and was the only syntactic form for the whole language. (Expressions used a shunting yard algorithm to desugar into a sequence of headform.) The language included modules, classes, parameterics, functions, constraints, ..., whatever.
- naruhodo 4y agoWell, everything looks like a pile of dirt when the only tool you have is a Spad. ducks
- dvratil 4y agoI don't think this has anything to do with modern trends - := is a formal way of writing assignment (the widely used = is actually an equality sign), and has already been present in Pascal for decades (and other languages as well).
- Jtsummers 4y agohttps://en.wikipedia.org/wiki/ALGOL_58 https://en.wikipedia.org/wiki/ALGOL_58 ALGOL, the := in programming languages used for assignment comes from IAL which became ALGOL 58. It's definitely not a modern development. Go reintroduced it to popular mainstream languages, sort of. Except they still use = for assignment and := is used when it's also declaring a new variable.
- int_19h 4y ago:= for assignment ultimately comes from math, as do most operators in early Algol: https://www.masswerk.at/algol60/report.htm#2_3 https://www.masswerk.at/algol60/report.htm#2_3
- rafram 4y agoI’m not sure I’d := is a “modern trend.” Smalltalk had it circa 1972, but none of the modern-day hip languages I can think of do. Your latter example is a common syntax, but the colon is omitted with the type in most languages (TypeScript, Rust, etc.).
- charcircuit 4y agoX being a modern trend does not mean it was not done in the past. It doesn't mean that it hasn't trended in the past either.
- the_af 4y agoSo what does it mean then? It was done in the very distant past. It was done in the intervening time. And it's done now. "Modern" trend?
- SaddledBounding 4y ago> The proposed syntax is probably a consequence of a modern trend... ML uses `name: type = value`. It came out over a decade before C++ and just one year after C.
- cvoss 4y agoIt's not modern at all. Type system notation has been using x : T to say "x has type T" for at least 50 years. It's the standard in academia, and has existed in real-world programming languages since 1971. [0] [0] https://cstheory.stackexchange.com/questions/43971/why-colon-to-denote-that-a-value-belongs-to-a-type https://cstheory.stackexchange.com/questions/43971/why-colon...
- forrestthewoods 4y agoIt is an old idea and also a modern trend. Trends come and go. It is currently trendy. 90s fashion is also trendy right now. Which is great because a few years ago it was 80. The cycle continues!
- the_af 4y ago"Currently trendy" how? Scala and Kotlin, to name just a few established programming languages, use the ": type" suffix style. They are neither "recent" nor from the original Algol era.
- int_19h 4y agoIt depends on how you define "current", I suppose, but personally I'd consider Kotlin to be fairly recent.
- the_af 4y agoWell, Kotlin is from 2011 and Scala from 2004! 11 and 18 years ago, respectively. I'd say neither is recent by any reasonable sense of the word that would imply their syntax or conventions are "a current trend".
- int_19h 4y ago11 years is not all that much for a PL, especially if you count from the date it was first announced, rather than from the first stable release (which for Kotlin was in 2016). For example, Rust started in 2006, and Rust 1.0 was in 2014, so it's actually older the Kotlin - but I think it still qualifies as "new", and many still consider it not fully battle-tested. For another example, Python goes all the way back to 1991, with v1.0 in 1994. But it didn't really start to trend until early 00s.
- noobermin 4y agoAll the replies are missing something, does cpp2 have goto labels? What happened to them. Unless you now have named loops in modern C++ now this removing goto is problematic.