> Frink has special syntax for date values. You can write # 2001-08-12 # to mean the date 2001-08-12 Frink? Frink ? This Visual Basic erasure can not stand. The #-delimited date literal syntax has been found all over the VB family: Visual Basic, VBA, VBScript, and it persists to this day in Visual Basic .NET. Of course, being a VB syntax, it's completely cursed. You can put # 01/05/2023 # in a VB file, and what date…
We don't have to follow locale, we could just force ISO 8601 and there won't be any ambiguity.
Microfeatures I'd like to see in more languages
371–380 of 539 posts
Re: Microfeatures I'd like to see in more languages
#372Earlier quoted context omitted.
> I don’t know if they also allow it for hex numbers. They do e.g. Python >>> 0x_ab_cd_01_23 2882339107 or >>> 0b_0010_0100 36
Even C these days, although they chose ' instead of _ :-(
Re: Microfeatures I'd like to see in more languages
#373Earlier quoted context omitted.
If you manipulate strings in code using "+" (string concatenation symbol) from a user input you'd be in a world of hurt where you either do a lot of regex (which is ugly and unmaintainable) or you limit the user input to known characters only (which would be a bad user experience and later on your manager would ask you to lift such constraint anyway because they want to support a new feature from now on). Therefore y…
Not OP, but I'm still confused. Is this assuming that the language is naive in its implementation of string concatenation so it screws up Unicode? I'm just not sure what the syntax has to do with the semantics of string concatenation.
Re: Microfeatures I'd like to see in more languages
#374I really adore Python's iterable- and keyword-unpacking operators (*some_iterable, **some_mapping): arr = [0, 1, 2, 3, 4] head, *body, tail = arr # head=0, body=[1, 2, 3], tail=4 head, *rest = arr head, *_, tail = arr *_, tail = arr first, second, third, *rest = arr foo = {"a": 1, "b": 2, "c": 3} bar = {"b": 9, "x": -1} {**foo, **bar} # -> {"a": 1, "b": 9, "c": 3, "x": -1}
Mdist = lambda (x1,y1),(x2,y2): abs(x1-x2)+abs(y1-y2)
p1,p2=(1,2),(3,4)
Mdist(p1,p2) # 4Re: Microfeatures I'd like to see in more languages
#375My favorite is uniform function call syntax. In several languages (Nim, Koka, D, …), you can always write bar.foo(baz) instead of foo(bar, baz) and vice-versa. Another one from Nim is the implicit result variable. Instead of having to do this: func sum(nums: seq[int]): int = var result = 0 for num in nums: result += num return result you just do this: func sum(nums: seq[int]): int = for num in nums: result += num It…
> My favorite is uniform function call syntax. In several languages (Nim, Koka, D, …), you can always write bar.foo(baz) instead of foo(bar, baz) and vice-versa. To me, these are "Tell bar's foo to do something with baz." and "Tell foo to do something with bar and baz.". So being 'able' to flipflop the syntax is at least temporarily semantic'ly confusing.
Why is bar working with baz and not baz working with bar?
I struggle with this in Unity:
Player.collect(PickUp) // this?
PickUp.boost(Player) // ...or this?
Instead, the code should describe the interaction between the two units of state: onCollide(Player, Pickup)
If we structure our code like in the last example, it makes sense to weaken the `a.b` vs `b(a)` distinction, and instead use the dot as a kind of pipe-operator.Re: Microfeatures I'd like to see in more languages
#376Strongly-typed units and unit literals (e.g. 3mL, 10gal, 15m / 3s = 5m/s) AFAIK F# has these and that's about it
They can be implemented as a library C++ thanks to templates and user-defined literals, and there's a proposal to add them to stdlib based on one of the existing implementations: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p19...
Re: Microfeatures I'd like to see in more languages
#377Earlier quoted context omitted.
I'm fine with an array type that supports this, but not as the default. I've been bitten in the past by code that ran error-free while giving incorrect output due to this feature suddenly making the indexing valid. I'd prefer it to be opt-in somehow so that the default behavior for negatives is invalid, not silently wrong yet valid behavior.
Matlab has the opposite where your syntactically valid but mysteriously non-working code suddenly has a large array. EDIT: On the other hand, I think Matlab's array(end - number) indexing syntax is a good compromise of convenience and less error prone explicitness.
Re: Microfeatures I'd like to see in more languages
#378Earlier quoted context omitted.
Interestingly, there was once a solid effort to add a try operator to Go. While the proposal was quite well received, upon closer inspection it was realized it would be essentially useless in the real world as, given how the rest of the language works, you almost never would want to simply early return with the value received. The data revealed that the vast majority of the code in the wild that the syntax sugar woul…
In Rust, when you use `?`, it includes a step to convert the error type of the expression it was used on into the (possibly different) error type that the current function returns. So if you need to map low-level errors to high-level ones in a consistent way, you'd just do it once when defining that error type.
Re: Microfeatures I'd like to see in more languages
#379Earlier quoted context omitted.
Tail call optimization can get you that, too. If you've written Scheme and/or gone through SICP you might be familiar with this: you write a recursive function, with the recursive function call as the last thing the function does ('tail-recursion'), and the compiler/runtime is able to optimize those recursive calls out rather than consuming one stack frame of space per call ('tail call optimization'). Clojure has loo…
Oh I didn’t know it was kind of a workaround. I do like the fact that loop is not a function though but an expression like if or case. FWIW I think in Clojure you can use “recur” inside functions too to specifically indicate tail call recursion without relying on automatic optimization
I didn't think Clojure had any automatic optimization at all, due to the JVM not supporting it.
Re: Microfeatures I'd like to see in more languages
#380Earlier quoted context omitted.
No, but I think that was a good choice. In local code this is great, but in an interface contract being explicit about data type is a virtue.
For interfaces this would obviously not work (there is no implementation). But for class members it would. I think this concept works very well in typescript and F#.