Why make it complicated?
-
Can we talk about PHP functions with typehints too?
public static function foo(): string {
Practically every other language with similar syntax does this instead:
public static string foo() {
TIL PHP has statics.
Also, does PHP actually enforce the type declarations? I'd assume it would but knowing PHP...
-
TIL PHP has statics.
Also, does PHP actually enforce the type declarations? I'd assume it would but knowing PHP...
It enforces scalar types (string, int, etc) at runtime if you enable strict mode. There's also static analysis tools like PHPStan and Psalm that will flag issues at build time.
-
Older variants used DIM for arrays and LET for other variables. DIM was originally called that because it was setting the dimensions of the array.
In modern BASIC variants, DIM has become a backronym: "declare in memory".
TIL Backronyms and cuil BASIC technicalities
Much obliged all -
python:
a: str = 1
And then assign an int to a string just to mess with the interpreter.
-
Made with KolourPaint and screenshots from Kate (with the GitHub theme).
First time i used let it was to inline variable declaration with assignment . Can’t remember the language.
-
Older variants used DIM for arrays and LET for other variables. DIM was originally called that because it was setting the dimensions of the array.
In modern BASIC variants, DIM has become a backronym: "declare in memory".
Even older variants required both a let to declare the variable and a dim to set its size.
I remember a
REDIM
command, but I really can't remember what basic it's from. -
Made with KolourPaint and screenshots from Kate (with the GitHub theme).
Good, now invent a keyword for variables you don't want to declare the type. And now that you have a mix of keywords and identifiers on the same place, you can never update your language again.
Also, make the function declarations not use a keyword too, so you get the full C-style madness of code that changes meaning depending on what libraries you import.
-
More than you'd ever want to know: https://en.m.wikipedia.org/wiki/Let_expression
I doubted you until I got about halfway through this whole page. I concede tho--you are most correct lol
Still a decent read and for that I thank you -
Made with KolourPaint and screenshots from Kate (with the GitHub theme).
wrote on last edited by [email protected]Because sometimes that
let
can be replaced by other things likeconst
. Which can be managed statically by the machine and not by my (imperfect) ability to know if it's mutated or not -
And then assign an int to a string just to mess with the interpreter.
only the linter gives a hoot - the interpreter will happily leave that footgun for later
-
Older variants used DIM for arrays and LET for other variables. DIM was originally called that because it was setting the dimensions of the array.
In modern BASIC variants, DIM has become a backronym: "declare in memory".
In modern BASIC variants, DIM has become a backronym: “declare in memory”.
TIL. I always thought it was a backronym for
declare in (yo) momma
. -
Can we talk about PHP functions with typehints too?
public static function foo(): string {
Practically every other language with similar syntax does this instead:
public static string foo() {
Rust and TypeScript use the return-type-at-the-end convention as well.
-
Because sometimes that
let
can be replaced by other things likeconst
. Which can be managed statically by the machine and not by my (imperfect) ability to know if it's mutated or notOk but, in the second example you typically just put final or const in front of the type to denote immutability. I still don't see the advantage to the first declaration.
-
Because sometimes that
let
can be replaced by other things likeconst
. Which can be managed statically by the machine and not by my (imperfect) ability to know if it's mutated or notI think you can do
const thing = ... as const
to lock down the mutation? -
Rust and TypeScript use the return-type-at-the-end convention as well.
Python too.
-
Good, now invent a keyword for variables you don't want to declare the type. And now that you have a mix of keywords and identifiers on the same place, you can never update your language again.
Also, make the function declarations not use a keyword too, so you get the full C-style madness of code that changes meaning depending on what libraries you import.
wrote on last edited by [email protected]In C#, you can use 'var' to have an impilict type variable.
String name = ""
var name = ""
-
Python too.
And Kotlin.
-
Ok but, in the second example you typically just put final or const in front of the type to denote immutability. I still don't see the advantage to the first declaration.
oh for sure, but I think that's the rarer case for language implementions. Having a consistent structure with alternative keywords in static positions is just easier to develop an AST for. Personally my favorite language doesn't even allow for const values (except by convention) so it's really just a matter of preference
-
In C#, you can use 'var' to have an impilict type variable.
String name = ""
var name = ""
So, a keyword
-
Made with KolourPaint and screenshots from Kate (with the GitHub theme).
wrote on last edited by [email protected]Not to short-circuit the joke, but in this case, it's because the valid JavaScript version is...
let a
...and one of TypeScript's main design goals is to be a superset of JavaScript, that only adds syntax, and doesn't re-write it.
Beyond that, it's probably a case of some new language just using what the designer is familiar with.