4 ms·
Pike is described as a "dynamic" language, so I was expecting purely dynamic typing, yet the language uses Java/C-style variable declarations with explicit type
by pansa2 1y ago
Pike is described as a "dynamic" language, so I was expecting purely dynamic typing, yet the language uses Java/C-style variable declarations with explicit types.
It seems that these are (unsound) type hints, years before TypeScript made them cool:
> "If your program tries to put one type of value in a variable which was designed to hold another type of value, Pike may detect this" [emphasis mine]
https://pike.lysator.liu.se/docs/tut/fundamentals/index.md#type-checking https://pike.lysator.liu.se/docs/tut/fundamentals/index.md#t...
- speed_spread 1y agoGroovy has that too and it's quite the anti-feature. Pretend static typing is worse than useless, it's the MAC-10 of footguns.
- ch4s3 1y ago> it's the MAC-10 of footguns At least it might be shooting Nulls.
- cmrdporcupine 1y agoSounds like Julia, too. Also you'd think having the type signature would help with performance, but in some cases it can cause the VM to enforce a runtime type check where it wouldn't have before, imposing worse performance.
- 2mlWQbCK 1y agoNot sure what they are referring to, but it may be that you can declare things as having one of several types (e.g. int|string|void) or even that something can be any type at all (i.e. turn off static type-checking for that thing)? I do not think the type-checker will ever randomly decide to just not check a type given that you have provided types for it to check, but it was a long time ago since I had to read or write any Pike code.
- metalliqaz 1y agoI can turn off static type checking for a thing in C by using `void*`
- pansa2 1y agoLooks like there’s a `mixed` type, variables of which can hold values of any type. But at least that’s something you can `grep` for. A more subtle issue with type hints (as in TypeScript/Python, not sure if this applies to Pike) is that there are ways to work around the type system. You can get, for example, a variable of type `int` that actually holds a `list`: https://news.ycombinator.com/item?id=43508152 https://news.ycombinator.com/item?id=43508152
- yobbo 1y agoThe compiler will complain about incorrect types and (?) infer types where possible. "Mixed" types are resolved at runtime. There is a strict_types mode that will increase warnings/errors. One of the problems with Pike is that the mechanics of this and other things are effectively undocumented so you have to learn by experimenting and reading the source.