Rant about programming language trends 

I hate the trend of new languages using the syntax "name: Type" instead of the familiar "Type name" to declare variables.

If static types have been jolted on to your language as an afterthought, then sure, but what's the point if you're designing a language from scratch?

The colon is superfluous (adds horizonal length and visual clutter), and while I don't really care about the order of the name and type, "Type name" is very well established from the whole C lineage of syntax.

Maybe there's a lineage of languages as old as C where the norm was "name: Type" so you could argue (if that really is the case, I don't know) that neither syntax is more or less well established... But if you're designing a language specifically to replace C, C++, Java, etc. then you have no excuse IMO.

Culprits:
- Rust
- Kotlin
- Swift
- Zig
- Nim
- Hare
Follow

Rant about programming language trends 

@taylan
this explains why go does it different from c go.dev/blog/declaration-syntax

> Go’s declarations read left to right. It’s been pointed out that C’s read in a spiral! See [The “Clockwise/Spiral Rule”](c-faq.com/decl/spiral.anderson) by David Anderson.

i haven't used many of the languages you point out, but it really works well in go imho.

re: Rant about programming language trends 

@bonifartius

The more complex C declarations are sure hell, no defense from me for those. :blobcatjoy:

I had forgotten that even Go uses "name: Type", as a language designed by the designers of C no less...

IMO even Java does it better though, by just fixing the most stupid aspects of the C declaration syntax, and dropping explicit pointer and function-pointer types in favor of classes and generics. E.g.:

String[] foo; // Instead of "String foo[]" which is legal but considered bad style.

An interface with a single method is equivalent to a function type, so:

interface IntMapper {
int map(int x);
}

int[][] mapIntMatrix(int[][] original, IntMapper mapper);

Alternatively, using the built-in generic interface Function<T, R>:

int[][] mapIntMatrix(int[][] original, Function<Integer, Integer> mapper);

(Sadly type parameters can't be primitive types so we have to use the Integer class there.)

Nested type parameters:

HashMap<String, List<Function<X, Y>>> hashMapFromStringsToListOfFunctions;

If you combine the generics syntax with <> and the primitive array syntax with [] you can get wonky things like "List<X>[]" to mean array of lists of x, but that pretty much never occurs since primitive arrays are pretty much reserved for special cases in Java and you'll use List instead most of the time, like List<List<X>> instead of List<X>[].
Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.