I want more implicit typing in typed languages. Quite often the compiler knows exactly what type a function will return, but I still need to write it there. Sometimes it’s easy („int“), but what about HashSet >> Typescript does it well. F# (completely statically typed) too…
Microfeatures I'd like to see in more languages
121–130 of 539 posts
Re: Microfeatures I'd like to see in more languages
#122Earlier quoted context omitted.
Any language that supports overriding the index operation should support this. You should be able to do this in C# with a struct with a backing array, for instance. If you're going to do this, use the word "Circular" in it, and I would also insist that if a has 4 elements, then a[0] == a[4] == a[8]. In other words, you always just take the (positive) index modulo the size of the area. Then a[-1] is the same as a[N-1]…
Where would the circular indexing like that be useful?
I'm not sure I'd want it for every list, but there are certain places it's nice.
[1] https://www.allaboutcircuits.com/technical-articles/circular...
Re: Microfeatures I'd like to see in more languages
#123 let data = try? aFuncThatThrows()
Sometimes I just don't care about the reason for the exception and just want to know if it succeeded or notRe: Microfeatures I'd like to see in more languages
#124Re: Microfeatures I'd like to see in more languages
#125One of the best truly micro features I've seen recently (can't remember which langauge unfortunately - it wasn't a mainstream one), is general binary literal syntax of the form: 0x[de ad be ef 00] So much nicer than the usual condensed format. And I think it'd be valid syntax in any language that allows binary integer literal.
Re: Microfeatures I'd like to see in more languages
#126local const variables like JavaScript has them. You can declare variables with „let“ (mutable) or „const“ (immutable). This is really great when reading code, because you never have to check if some code may change the variable at some point. And you usually declare most variables as const. A lot of languages provide immutable variables only for class members or statics, but not for local variables.
I really like Scala’s `val` vs `var`.
Re: Microfeatures I'd like to see in more languages
#127Python's `with` Function composition operators eg a |> b # Call `b` with `a` as an argument b Then you can do something like let x : Map = collect map(entries) |> flatten
It's very common already: try-with-resource (java), using (C#), bracket (haskell), unwind-protect (common-lisp), ... though it the latter two it's more of a building block.
Also building block: languages with a convenient and "unrestricted" syntax for anonymous function can just use that e.g. Smalltalk, Ruby, ... in Ruby a "with" is usually just passing a block to the corresponding object's constructor:
# python
with open(...) as f:
...
# ruby
File::open(...) do |f|
...
endRe: Microfeatures I'd like to see in more languages
#128Re: Microfeatures I'd like to see in more languages
#129I have long wondered why Ruby's symbols aren't in every language.
They exist in K/Q. A single-word identifier-shaped symbol begins with a backtick, or a multi-word symbol can be created with a backtick and double quotes. A sequence of symbols is a vector literal, and is stored compactly. For example: `apple `"cherry pie" `one`two`three Many languages will intern string literals implicitly, or allow a programmer to explicitly intern a string; for example Java's "String.intern()". Th…
So does a long-running program which generates new symbols on the fly.
Re: Microfeatures I'd like to see in more languages
#130Earlier quoted context omitted.
and vice-versa Doesn't the reverse pollute the function namespace? If every obj.fun() can be written as fun(obj), doesn't that cause ambiguity with a previously imported global function fun()?
> doesn't that cause ambiguity with a previously imported global function fun()? Yes, although overloading can mitigate the issue.
In Nim however I've only had it happen a handful of times in a few years. Then you just need to use the module name to qualify it, or change your imports.