One 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.
A lot of languages allow underscores in numeric literals. Something like 10_000. You can put them anywhere and they get ignored. I don’t know if they also allow it for hex numbers.
Microfeatures I'd like to see in more languages
141–150 of 539 posts
Re: Microfeatures I'd like to see in more languages
#142Haskell has almost all of these. > Instead of writing 10000500, you can write 10_000_500, or 1_00_00_500 https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/nume... > Balanced string literals https://hackage.haskell.org/package/raw-strings-qq-1.1/docs/... > Generalized update syntax Use Lens. `fileName %~ max 2` > you can write the sequence 1, 2, … n-1 as 1.. Yup. `[1,2..n-1]` There's far more to it, you have acc…
> In Haskell you use hash has a prefix instead of colon.
Can you give an example?
Re: Microfeatures I'd like to see in more languages
#143Python'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
Re: Microfeatures I'd like to see in more languages
#144Re: Microfeatures I'd like to see in more languages
#145Elixir's sigils are amazing. There are date sigils that allow you to do what the OP does: ~N[2023-01-01 12:00:00] But you can also define your own sigils to create new "custom syntax" for almost any struct. Kind of a special case of reader macros, I guess. Very convenient.
Re: Microfeatures I'd like to see in more languages
#146Earlier quoted context omitted.
Depends on the size of your codebase and how many people work on it. Once you have 20 years of code written full time by 200 developers in your monolith, finding the constants file out of 400 different subsystem's constant files for a given subsystem that you've never seen before can become a legitimate and challenging pain.
Totally true. I don't know if IDEs commonly have a feature like, "find this value, regardless of how it's expressed" (even better yet, fuzzily, to catch typos), but I think that's the proper general solution. It's a good idea to consider a constants file earlyish, while everything still fits in your head. I'd say in the case of such a sprawling system, make a constants module, and it can have different files for diff…
Re: Microfeatures I'd like to see in more languages
#147I like how functions in js can be `arg => result`. In F# I have to do `fun arg -> result` with the `fun` keyword. It makes sense since `MyArgType -> MyResType` is a type signature in f#, but I feel like the compiler can just check if the arguments are references to types or are argument bindings.
# Multiline Lists/Arrays ####
I like how F# doesn't require delimiters for multiline lists.
So I can do `let myList = [1; 2; 3]` or
let myList = [
1
2
3
]
# Regex Literal ####I like how in Crystal instead of doing `/my[regex]/` i can do `%r(my[regex])` where the parenthesis can be any brace type (like "(", "{", "# Argument Accessor Shorthand ####
In Crystal, you can use an ampersand to bind and access a property on an object, instead of writing the verbose form with a function.
So this
["a", "b"].join(",") { |s| s.upcase }
can be written as ["a", "b"].join(",", &.upcase)
If this were available in F#, for example, instead of ["a"; "b"]
|> List.map (fun s -> s.ToUpper())
|> String.concat ","
I could do ["a"; "b"]
|> List.map &.ToUpper()
|> String.concat ","Re: Microfeatures I'd like to see in more languages
#148IE
a = 1; b = 2
assert a == b
Will fail with error like: Assertion failed,
a == b
Left is 1
Right is 2
So you don’t have a bunch of assert-functions; you just assert anything and it will spit out a decent error.Re: Microfeatures I'd like to see in more languages
#149> [In Chapel] there’s the config keyword. If you write config var n=1, the compiler will automatically add a --n flag to the binary. As someone who 1) loves having configurable program, and 2) hates wrangling CLI libraries, a quick-and-dirty way to add single-variable flags seems like an obvious win. Letting people define configurable variables at their call site is incredibly valuable, even if you don't have compile…
That seems like a great way to get amazingly hard to replicate bugs or odd behaviours if different subsystems use different values for the default.
Re: Microfeatures I'd like to see in more languages
#150> Second, what if parameter blocks were abstractable? Sounds like a great way to make unreadable code #define STANDARD_EXP_PARAMS ... // I hit gotodef on func(...) and got here. What are the arguments? void func (STANDARD_EXP_PARAMS) { // ... long function body ... x = y; // What is the type of x? Is it an argument or a local? } I'd really be irritated if someone ever used this feature, optimizing for lines written i…