Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

81–90 of 539 posts

Re: Microfeatures I'd like to see in more languages

#81

I love all the sugar of Kotlin, but there is one thing I miss, and it is the indexing of arrays of Python when pulling out part of an array.

Kotlin is so close on so many things, but then keeps messing up. arrayOf(1, 2, 3) - why not [1,2,3]? emptyArray() - why not []? mapOf("key" to "value") - why not {key => value}? These are all solved problems. Why would they make up some harshly suboptimal syntax?

I am not that familiar with Kotlin, but these seems better than the syntax primitives from a language design perspective (I greatly recommend the “Growing a language” presentation done by Guy Steele), these are ordinary functions that are well-known from other parts of the language, not an added “hack” that has a one-off use. If you were to use a concurrent hashmap implementation you no no longer can use the syntactic sugar, and writing against an implementation is quite common in Java (which plays quite a big role in the design of Kotlin), e.g. having a List in the interface, instead of ArrayList.

Re: Microfeatures I'd like to see in more languages

#82
post #32
post #15

> Instead of writing 10000500, you can write 10_000_500, or 1_00_00_500 if you’re Indian. I hate this so much. It means I can't grep for a constant.

If you have constants repeated throughout the codebase, you can pull them into a constants file, and then you can go to that file, navigate to the definition of interest, and use your IDE of choice to find usages. You'll also be able to give these constants semantically significant names, and comment next to them providing derivations or citations. And of course, if it's a mistaken or outdated value, you can change i…

I'm in the same boat as GP. Typically, I grep such things when I am not familiar with the codebase, so I can't change where constants are defined, and I do not know where to find such a file.

Re: Microfeatures I'd like to see in more languages

#83
post #51
post #32

Earlier quoted context omitted.

If you have constants repeated throughout the codebase, you can pull them into a constants file, and then you can go to that file, navigate to the definition of interest, and use your IDE of choice to find usages. You'll also be able to give these constants semantically significant names, and comment next to them providing derivations or citations. And of course, if it's a mistaken or outdated value, you can change i…

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.

This so hard. A constant that replaces a magic number like 5 that is ungreppable, or a constant for a precise number like the physical constants - sure. A constant that replaces a number like 404 or 500 that you want to be able to easily grep across heterogenous code bases for? Pass.

Re: Microfeatures I'd like to see in more languages

#84
post #76

Python'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

I don't get it, how are |> and <| any different from parentheses?

Re: Microfeatures I'd like to see in more languages

#85
post #67

> If you look at something like numpy functions, so many of them share the exact same parameter definitions. What if you could write def log(standard-exp-params) instead of having to write them out every single time? They're not actually written out every time, the issue is mostly documentary (and it would be nice if Python or Sphinx ever had a good solution). And numpy actually has a bunch of generators for that e.g…

I don't use Numpy but it sounds like they're describing *, ** operators. default_args = ('x', 'y', 'z') default_kwargs = {'p': 'p', 'q': 'q', 'r': 'r'} def printer(x, y, z, /, *, p, q, r): print(f'x={x} | y={y} | z={z} | p={p} | q={q} | r={r}') printer(*default_args, **default_kwargs) # x=x | y=y | z=z | p=p | q=q | r=r EDIT: Formatting.

Yes but also that lacks most of the documentation so it's not great.

If you have multiple callables taking these parameters documenting them is awkward, by default help/pydoc and sphinx will tell you that the parameters are `default_args` and `default_kwargs`, but that's not actually true, those are just intended as shortcuts / helpers .

Re: Microfeatures I'd like to see in more languages

#87
post #77

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…

Rust does a pretty decent job of this, particularly around functions that return collect().

But yeah, C++ has a ways to go on type inference.

Re: Microfeatures I'd like to see in more languages

#88
post #76

Python'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

I don't get it, how are |> and <| any different from parentheses?

Chaining without nesting.

Re: Microfeatures I'd like to see in more languages

#89
post #4

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. 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…

I’m not so sure about that. Did you ever check out extension methods in C#, they are a bit like what you’re describing, but not so radical.

Re: Microfeatures I'd like to see in more languages

#90
post #51

Earlier 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.

This so hard. A constant that replaces a magic number like 5 that is ungreppable, or a constant for a precise number like the physical constants - sure. A constant that replaces a number like 404 or 500 that you want to be able to easily grep across heterogenous code bases for? Pass.

Is that 500 the HTTP error or 500 the adhoc limit we put on the number of user uploads or a 500, representing half a kilobyte?
Post reply on HN