Absolutely damned is combination of Kotlin's several features: 1. Lambda functions can be defined with `{}`. 2.`foo(bar, somefunc)` is the same as `foo(bar) somefunc`. In other words, if the last parameter is a function, it can be provided AFTER closing parenthesis. 3. Interfaces that require only one method can be implemented on-side with a lambda function (i.e. `{}` syntax for no-param function). Combined those thr…
What exactly do you mean by "damned" here?
Microfeatures I'd like to see in more languages
361–370 of 539 posts
Re: Microfeatures I'd like to see in more languages
#362Earlier 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…
You haven't understood the problem at all. No wonder, few people do any sort of bare metal programming. It's not about defining constants, or even writing code at all, it's about figuring out what this arbitrary piece of code is doing based on hardware datasheets . You search for constants defined in the datasheet in the piece of code you are analyzing to determine what it does, or where does it do specific things...
Re: Microfeatures I'd like to see in more languages
#363I have long wondered why Ruby's symbols aren't in every language.
CL-USER 69 > :a-keyword-symbol
:A-KEYWORD-SYMBOL
Keywords with a similar name are identical: CL-USER 70 > (eq :a-keyword-symbol :a-keyword-symbol)
T
One can't set keyword symbols to another value: CL-USER 71 > (setf :a-keyword-symbol 3)
Error: Cannot setq :A-KEYWORD-SYMBOL -- it is a keyword.
They have certain features of normal symbols, like a property-list with keyword/value pairs.Re: Microfeatures I'd like to see in more languages
#364Earlier quoted context omitted.
>> Symbols > In Haskell you use hash has a prefix instead of colon. Can you give an example?
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/over... You can do all sorts of things with them. Use them like symbols in Scheme, say to name fields `get #name user` or to access database tables, etc. But what's even more interesting is that the name is reflected up into the type. `get #name user` won't fail at runtime. Your database table name can be checked at compile time.
Re: Microfeatures I'd like to see in more languages
#365My 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.
Re: Microfeatures I'd like to see in more languages
#366Earlier 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]…
You'd have to care about the difference between indexing with a literal and indexing with variables of different types/widths, and how indexing with a variable interacts with the size of the area. For instance if you have an int array that contains the numbers 1-250 and you index with a uint8 variable i, for (uint8 i = 247; i++;) { // print circ_arr[i] } for the values of i near the overflow points of the circular ar…
You’d need a way to get that type, for example as
float a[10,20] // two-dimensional array of floats
typeof(a.dims(0)) i = 0 // modular type with values in [0,9]
typeof(a.dims(1)) j = 0 // modular type with values in [0,19]
or, slightly neater: auto i = a.indextype(0)
auto j = a.indextype(1)
Ugly syntax, but in a modern language, most code would probably do something like for (i,j,value) in a
where the types are inferred.Having those modular types means the compiler would do the arithmetic correct for the array, while the negative literals allow programmers to specify “last” and “next to last” correctly.
Re: Microfeatures I'd like to see in more languages
#367My 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…
Initializing at what type and value?
Re: Microfeatures I'd like to see in more languages
#368Re: Microfeatures I'd like to see in more languages
#369Earlier 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]…
What 'mod' is for, innit.
Re: Microfeatures I'd like to see in more languages
#370Nested json dictionary lookups with default fallback, for scenarios where any of the sub-dictionaries could be null or missing a key. Write parseDateTime(config["a"]["b"]["c"]) safely as a oneliner. Haven't seen any language solve this in a neat way, without catching indexerror exceptions or ugly chaining of null-conditionals and empty dictionaries as fallback-values.