framapiaf.org est l'un des nombreux serveurs Mastodon indépendants que vous pouvez utiliser pour participer au fédiverse.
Un service Mastodon fourni par l'association d’éducation populaire Framasoft.

Administré par :

Statistiques du serveur :

1,4K
comptes actifs

#generics

1 message1 participant0 message aujourd’hui

Sitting in PhpStorm and trying to get type hinting to work for calling generic functions.
I assume `$result` should get the type `T` and `$x` should be parsed as `int`, but the editor gives me no hint at all.
Is this even supposed to work?
```
/**
* @template T
* @param callable(): T $fun
* @return T
*/
function call(callable $fun) {
$result = $fun();
return $result;
}

$x = call(fn() => 1);
```
phpstan.org/r/76b4d50f-dd91-4e
#php #phpStorm #generics #phpDoc

phpstan.orgPlayground

"Small" things that I highly appreciate about Kotlin coming from Java - Chapter 1

Inline functions with reified type parameters:

𝚒𝚗𝚕𝚒𝚗𝚎 𝚏𝚞𝚗 <𝚛𝚎𝚒𝚏𝚒𝚎𝚍 𝚃> 𝚍𝚘𝚂𝚘𝚖𝚎𝚝𝚑𝚒𝚗𝚐(𝚟𝚊𝚕𝚞𝚎: 𝚃)

kotlinlang.org/docs/inline-fun

No more passing classes as parameters. No more super type tokens. It just works.

Kotlin HelpInline functions | Kotlin
#Kotlin#Java#JVM

It's getting late and I should go to bed, but I wanted to play with #ctran.

I thought I'd see how much faster it is to convert my `array of TToken` to a `TList<TToken>`.

Turns out, twice as fast!

Basically, when you concat() an array, the entire array is copied every time. With a TList.Add(), it just adds a pointer to the end.

The DOS executable is slightly larger (438KB vs 446KB), but the it's worth it for better efficiency and code readability.

#Swift #Generics

Hello my beautiful kind helpful Swift people

I have basic question about generics, “some”, “any” and such. Maybe you can nudge me in the right direction?

How would you fix this code so it compiles? Can it be done even?

What it does: trying to archive and unarchive some Codable+Sendable values, without caring about the exact type

It can assume that there are no mixed types, i.e it always works with [ResultRecord] or [OtherTypeConformingToResultRecordType], but no mixing

A répondu dans un fil de discussion

@jhx You asked for it, so I'll answer it:

Imho, C++ design is broken from the very beginning. It wanted to provide #OOP language constructs, still maintaining full #C compatibility (which already failed many years ago, cause the languages took different roads).

It combines #exceptions (IMHO generally a bad idea) with explicit resource management (an *awful* idea, forcing you to use #RAII which will in turn mandate creation of purely "technical" classes, just to manage resources).

It wanted #generics, but that's impossible without breaking C compatibility, so it came up with #templates, actually a #preprocessor on steroids.

Overloading also doesn't fit into the simple C library ABI (where #linker symbols are named just like the function), so it came up with "name mangling" ... which is especially horrific because it is *not* standardized.

Ah well, I could go on 😂

La nuance entre le trait compilé statiquement et celui exécuté dynamiquement est assez subtile. Et je me suis déjà bien fait mordre par cette subtilité de Rust.
<br>&#8212; <a href="blog.metrink.com/blog/2018/03/" title="Direct link">Direct link</a> - nicolas-delsaux.hd.free.fr/Sha

Metrink BlogRust: Trait Objects vs Generics | Metrink BlogPar William Speirs