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?
Microfeatures I'd like to see in more languages
81–90 of 539 posts
Re: Microfeatures I'd like to see in more languages
#82> 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…
Re: Microfeatures I'd like to see in more languages
#83Earlier 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.
Re: Microfeatures I'd like to see in more languages
#84Python'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
#85> 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.
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
#86Re: Microfeatures I'd like to see in more languages
#87I 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…
But yeah, C++ has a ways to go on type inference.
Re: Microfeatures I'd like to see in more languages
#88Re: Microfeatures I'd like to see in more languages
#89My 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…
Re: Microfeatures I'd like to see in more languages
#90Earlier 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.