News for hackers. Stuff that matters.
Re:Elixir – Why the dot (when calling anonymous functions)? by bnchrch on Monday August 14, 2023 @12:45PM (#37123178)
For those of you who are interested by Elixir but find the lack of static typing an issue here are somethings to be aware of:

1. Static Typing is planned and currently the top priority of the team

https://elixir-lang.org/blog/2022/10/05/my-future-with-elixi...

2. There is a type checking tool

https://github.com/jeremyjh/dialyxir

3. You can go a long way with pattern matching and guides in the meantime and have alot more guarantees that a typical dynamic typed language.

Re:Elixir – Why the dot (when calling anonymous functions)? by sbjs on Monday August 14, 2023 @12:55PM (#37123348)
I'm glad we're in the age of static typing. The age of dynamic typing as a response to incorrect static typing was a necessary evil. We had to take a break from broken languages in order to realize what needed to be fixed in those languages. I'm convinced that JavaScript will eventually be one of the best, fastest, and safest languages, as long as we keep this cycle up of abandoning necessary languages and returning to them with very thorough fixes to much better understood and detailed problems with them.
Re:Elixir – Why the dot (when calling anonymous functions)? by hosh on Monday August 14, 2023 @01:03PM (#37123489)
I'm convinced that until Javascript makes it easy to do the right thing by default (instead of its current state of doing many wrong things by default) the Javascript ecosystem will continue to have a lot of low-quality library code intermixed with a few high-quality ones. My neutral regard for JS had rapidly degraded when I had to actually start writing code in it or understanding code others have written.
Re:Elixir – Why the dot (when calling anonymous functions)? by sbjs on Monday August 14, 2023 @01:13PM (#37123633)
What ways does do the wrong things by default? I can't think of a single one. You might say, well, == is broken and you have to use ===, but that's not "the wrong thing by default" unless you assume that == is what ought to be the default operator and === ought to be secondary. But that assumption has to come from somewhere, and probably comes from the fact that other languages do it that way. But there's nothing inherently incorrect about === being the default operator and == being the rare secondary one. I think the same principle applies to any example you might be able to give me: if you assume that another language is objectively right, only then can you say that JavaScript is objectively wrong in comparison to that language which apparently descended from the heavens.
Re:Elixir – Why the dot (when calling anonymous functions)? by david422 on Monday August 14, 2023 @01:25PM (#37123772)
Well === was added to make up for deficiencies in == so seems reasonable that saying == is the default that does things incorrectly.
Re:Elixir – Why the dot (when calling anonymous functions)? by wtetzner on Monday August 14, 2023 @01:50PM (#37124156)
I would argue that implicit conversions in a dynamically typed language is a mistake in general. It's the "wrong thing by default" in the sense that it's too easy to write broken code by accident. And I think that's what is usually meant by "wrong thing by default".

I think if you really want implicit conversions, then you want to do what Perl does (never thought I'd say that): different operators for different types.

Re:Elixir – Why the dot (when calling anonymous functions)? by mjburgess on Monday August 14, 2023 @01:54PM (#37124217)
You're assuming a certain sort of perspectivalism: the only reasons X could be better than Y is that, from someone's pov, some language has X.

This is kinda insane. People can give reasons X is better than Y on grounds of various theoretical virtues of X -- that has nothing to do with a preference for any language.

Here's an example virute:

Behaviour should be consistent unless specialised. When specialised it should be obvious which specialisation is chosen.

(Violation: basically all of js' operators).

Re:Elixir – Why the dot (when calling anonymous functions)? by airstrike on Monday August 14, 2023 @03:35PM (#37125743)
Re:Elixir – Why the dot (when calling anonymous functions)? by claytongulick on Monday August 14, 2023 @05:08PM (#37126822)
It's pretty easy to footgun when you're mixing event/callback based flow with promises/async.

It's really easy to forget a closure in an event driven function and to produce difficult to debug, error prone code.

A classic example I just screwed up:

    export function getSFTPConnection(options) {
        let key = readFileSync(options.keyfile_path, 'utf8');
        let ssh = new ssh2.Client();
        return new Promise(
            (resolve, reject) => {
                ssh.on('error', reject);
                ssh.on('ready', () => {
                    ssh.sftp((err, sftp) => {
                        resolve(sftp);
                    });
                });
                ssh.on('close', (err) => {
                    reject(new Error('SSH connection closed: ' + err));
                })
                ssh.connect(
                    {
                        host: options.host,
                        username: options.username,
                        privateKey: key,
                    }
                );
            }
        )
    }
The bug here isn't obvious, at least to me - but it caused me much heartache and pain because I was moving too fast and not thinking - but a good example of unexpected behavior by default.

The bug is that there's not a closure around the ssh instance, so if you call this function multiple times it'll actually return the same connection instance.

The extra fun part of this bug is that the code worked - but because I was using the same instance, when I'd download multiple files in parallel, it would interleave the data, corrupting the files.

And the thing is, I know better. I've been doing js for decades.

I love js, but stuff like this is pretty frustrating, and can be a nightmare for new devs.

Re:Elixir – Why the dot (when calling anonymous functions)? by minitech on Monday August 14, 2023 @05:57PM (#37127310)
> The bug is that there's not a closure around the ssh instance, so if you call this function multiple times it'll actually return the same connection instance.

I’m not entirely sure what you mean by this, but it doesn’t sound like a correct diagnosis. Each call to `getSFTPConnection` creates a new `ssh2.Client` instance (unless `ssh2.Client`’s constructor does something weird), and the promise can only resolve with the value `ssh.sftp` passes (although there’s a missing error check).

Re:Elixir – Why the dot (when calling anonymous functions)? by claytongulick on Monday August 14, 2023 @08:10PM (#37128478)
Yes, you're 100% correct, I mixed some stuff up when I was posting the code for simplicity.

Bad example!

Re:Elixir – Why the dot (when calling anonymous functions)? by plorkyeran on Monday August 14, 2023 @07:56PM (#37128380)
> The bug is that there's not a closure around the ssh instance, so if you call this function multiple times it'll actually return the same connection instance.

You've either adjusted the code for posting or you misunderstood what the problem was, because no, that's not the case. The ssh variable is local to the getSFTPConnection function and is not reused between multiple calls to the function, and throwing a pointless extra closure in there wouldn't do anything.

Re:Elixir – Why the dot (when calling anonymous functions)? by bee_rider on Monday August 14, 2023 @05:37PM (#37127133)
== was already a silly operator, === is just ridiculous.
Re:Elixir – Why the dot (when calling anonymous functions)? by Dylan16807 on Monday August 14, 2023 @08:28PM (#37128599)
It's a huge stretch to claim that === isn't secondary to ==.
Re:Elixir – Why the dot (when calling anonymous functions)? by frou_dh on Monday August 14, 2023 @01:09PM (#37123580)
Maybe it's just me but there's something fundamentally unappealing about bolt-on static type-systems on top of pre-existing dynamic languages. Sure, what's come about with e.g. TypeScript is pragmatic and very useful, but if imagining a future utopia then TS/JS++ would not feature in the dream.
Re:Elixir – Why the dot (when calling anonymous functions)? by sbjs on Monday August 14, 2023 @01:19PM (#37123711)
Why not? I can't think of anything off the top of my head that I think is fundamentally broken about TypeScript, or even that I strongly dislike about it.
Re:Elixir – Why the dot (when calling anonymous functions)? by frou_dh on Monday August 14, 2023 @01:41PM (#37124027)
- Too many statements instead of expressions.

- Lacks structural pattern-matching.

- Lacks first-class sum-types (although they can be clumsily encoded as objects with "kind" properties).

These are the sort of things people appreciate in "good" static languages, as opposed to the static languages you alluded to that Python/Ruby/JS/etc were rebelling against in the 2000s.

Re:Elixir – Why the dot (when calling anonymous functions)? by wtetzner on Monday August 14, 2023 @01:52PM (#37124190)
Depending on who you ask, the fact that the type system is unsound could be considered a form of brokenness.
Re:Elixir – Why the dot (when calling anonymous functions)? by LadyCailin on Monday August 14, 2023 @01:38PM (#37123980)
Its type system is apparently Turing complete. That’s a pretty major flaw, imo. Meaning that static analysis isn’t always possible.
Re:Elixir – Why the dot (when calling anonymous functions)? by consilient on Monday August 14, 2023 @06:26PM (#37127552)
Turing complete type systems are extremely common. C#, C++, Java - it's hard to avoid if you have subtyping and generics. In practice it almost never comes up.
Re:Elixir – Why the dot (when calling anonymous functions)? by consilient on Monday August 14, 2023 @06:56PM (#37127832)
A small sample:

The existence of `any`; worse yet, the use of `any` in the standard library.

Mutable arrays are treated as covariant: the classic `cats : Cat[] ; animals: Animal[] = cats; animals.push(dog);` problem.

Methods are both co- and contravariant in their arguments by default, which is comically wrong. Member variables which are functions, meanwhile, are handled correctly.

`readonly` is a lie:

    const test: {readonly a: number } = {a: 0}
    const test2: {a: number} = test
    test2.a = 5
`Record<string, string>` is actually `Record<string, string | undefined>`. There's no way for an interface to specify that it really does return a value at any string index (e.g. for a map with a default value).

`{...object1, ...object2}` is typed as the intersection `typeof object1 & typeof object2`, which is not correct.

    const a: {a: 5} = {a: 5}
    const b: {a: 4} = {a: 4}

    const spread = <L, R>(l: L, r: R): L & R => ({...l, ...r})
    const impossible: never = spread(a, b)
You have to resort to bizarre conditional type hackery to control when unions distribute and when they don't.

You can constrain generics as `<T extends string>foo(t: T) => ...` but not `<string extends T>foo(t: T) => ...`, which makes many functions (e.g. Array.includes) much too strict about what they accept.

Re:Elixir – Why the dot (when calling anonymous functions)? by lvass on Monday August 14, 2023 @02:04PM (#37124358)
It's a nightmare, not a dream, if the language is mutable. Mutability is the worst and least fixable issue with almost every popular language today.
Re:Elixir – Why the dot (when calling anonymous functions)? by ecshafer on Monday August 14, 2023 @02:04PM (#37124362)
I don't really like Typescript, I think I would rather just code in Javascript. Typescript adds a lot of structure and tries to shoehorn more of a Java like programming style. A lot of the type checks seem unnecessary. If I am going to use types I would rather use Fable or ReasonML, something that really just has types from the start.
Re:Elixir – Why the dot (when calling anonymous functions)? by rdevsrex on Monday August 14, 2023 @02:04PM (#37124360)
Interesting, will check out. I am still evaluating Gleam, a language that's targets beam, but the compiler is written in Rust. It has actual strong typing, and I rather like it's Rust like syntax.
Re:Elixir – Why the dot (when calling anonymous functions)? by eggy on Monday August 14, 2023 @02:30PM (#37124733)
I was too until they strayed from the more Standard ML-like syntax to Rust-like syntax all for trying not to alienate the Algol crowd and Rust aficionados. For popularity. I like APL, BQN, and J so I'm not swayed by it.
Re:Elixir – Why the dot (when calling anonymous functions)? by bnchrch on Monday August 14, 2023 @03:28PM (#37125671)
I really like Gleam, and I am a huge fan of more being built on the EVM.

Personally I want the EVM to (eventually) get the same level of adoption and mindshare as the JVM.

And currently wider Elixir use/education seems like the path to that.

Re:Elixir – Why the dot (when calling anonymous functions)? by comex on Monday August 14, 2023 @06:47PM (#37127724)
EVM is the Ethereum Virtual Machine. You mean BEAM, right?
Re:Elixir – Why the dot (when calling anonymous functions)? by yellowapple on Monday August 14, 2023 @11:04PM (#37129686)
EVM stood for "Erlang Virtual Machine" (of which BEAM is one implementation) before Ethereum even existed.
Re:Elixir – Why the dot (when calling anonymous functions)? by octacat on Tuesday August 15, 2023 @09:01AM (#37133431)
Except majority of people uses BEAM name for the last 13 years. Erlang VM or Erlang Virtual Machine is ok too. EVM name is just super not-popular, idk why.
Re:Elixir – Why the dot (when calling anonymous functions)? by yellowapple on Wednesday August 16, 2023 @10:01PM (#37156246)
Erlang's creators use EVM, which is where I learned it from. Not sure why it didn't catch on, either; I guess for a long-enough while BEAM was the only EVM implementation in common use, so it became the Xerox™ or Velcro™ of Erlang virtual machines lol
Re:Elixir – Why the dot (when calling anonymous functions)? by arturkane7 on Monday August 14, 2023 @02:24PM (#37124647)
What’s currently the best static typed language for web development?
Re:Elixir – Why the dot (when calling anonymous functions)? by bnchrch on Monday August 14, 2023 @02:39PM (#37124868)
Typescript, by a large and deserved margin.
Re:Elixir – Why the dot (when calling anonymous functions)? by ak_111 on Monday August 14, 2023 @02:46PM (#37124998)
Should have added other than Typescript :)
Re:Elixir – Why the dot (when calling anonymous functions)? by bnchrch on Monday August 14, 2023 @02:54PM (#37125144)
Then I would vote Go (best stdlib in the business), then Java.
Re:Elixir – Why the dot (when calling anonymous functions)? by weatherlight on Monday August 14, 2023 @04:50PM (#37126635)
It's not sound :(. Type systems should be bomb proof or get out of the way.
Re:Elixir – Why the dot (when calling anonymous functions)? by mjhay on Monday August 14, 2023 @08:45PM (#37128731)
Typescript's unsoundness isn't a good thing, but it is way down the list of type-unsafe things inherent in the Boschian nightmare that is frontend development.

Compile-to-JS languages add a big impedance mismatch when you inevitably need to use JS libs. Typescript's JS + types philosophy helps with this issue (it still sucks though).

Re:Elixir – Why the dot (when calling anonymous functions)? by deathtrader666 on Monday August 14, 2023 @03:01PM (#37125278)
Rescript
Re:Elixir – Why the dot (when calling anonymous functions)? by giraffe_lady on Monday August 14, 2023 @03:48PM (#37125918)
ReScript is excellent. Same type system as ocaml, which is IMO the sweet spot between power and straightforwardness. You lose the "you can represent ANYTHING" capability of TS which is both a pro and a con. In exchange it's much simpler to work with and has excellent type inference for day to day work.

The externals binding system for JS libs works well for integrating libraries. And react bindings are included in the standard lib, they also work great. The compiler is fast and produces generally quite reasonable JS.

You could argue that it's not "better" than elm in a theoretical sense. But for practical work it's much closer to the mainstream of web dev in mindset and syntax. Easier to learn, much easier to integrate with other frameworks or into existing teams & codebases. And it's less opinionated about rendering: it generally assumes you're using react, but you don't have to and it can emit anything if you do some extra work wiring it up. I have used it with node and even, irresponsibly, deno fresh.

Been using it whenever I can for frontend stuff for a year now and haven't enjoyed a language this much since... well... elixir.

Re:Elixir – Why the dot (when calling anonymous functions)? by ak_111 on Monday August 14, 2023 @04:00PM (#37126067)
The only popular choices: Typescript, Java, Go (although I don't think it is that popular as a webapp backend language) or C# (I think).
Re:Elixir – Why the dot (when calling anonymous functions)? by weatherlight on Monday August 14, 2023 @04:50PM (#37126642)
Rescript, 100%
Re:Elixir – Why the dot (when calling anonymous functions)? by consilient on Monday August 14, 2023 @06:15PM (#37127463)
Purescript has by far the strongest type system of any mature compile-to-js language, good FFI, footprint comparable to react.

Elm is a heavily stripped down purescript, plus an ambiguously-benevolent dictator for life. Also terrible interop. It's a good learning environment but I would strongly recommend against using it for anything big.

Rescript is basically Ocaml with half-js syntax.

Typescript is bizarre. On a scale from 0 (C) to 10 (Haskell), it's a 12, a 6, and a 2 duct taped together. It's got some incredibly powerful features (template literals, conditional types), but it's missing most of the standard "advanced"-but-production-ready type system features (e.g. no HKTs, no type-directed emit) and the foundation is absolutely riddled with soundness holes.

Re:Elixir – Why the dot (when calling anonymous functions)? by bPspGiJT8Y on Monday August 14, 2023 @06:17PM (#37127479)
Also worth mentioning Idris, although its tooling and ecosystem are still pretty much nonexistent.
Re:Elixir – Why the dot (when calling anonymous functions)? by consilient on Monday August 14, 2023 @06:21PM (#37127510)
Yeah, that's what I meant by "mature". Agda also has a js backend, but neither one can really stand alone. Haskell is closer, but GHCJS is still very much a second class citizen of the ecosystem.
Re:Elixir – Why the dot (when calling anonymous functions)? by bPspGiJT8Y on Monday August 14, 2023 @06:45PM (#37127710)
Clean also has WASM as the compile target via its IR, and its tooling is great. Unfortunately though I couldn't find any sort of a community when I was looking into it, but other than this the language looks quite mature and very industry-oriented. Then there's Lean which also can compile to WASM via some sort of a bridge, it has decent tooling but the ecosystem is still nonexistent.
Re:Elixir – Why the dot (when calling anonymous functions)? by lmm on Monday August 14, 2023 @06:25PM (#37127544)
Few people on the web side know about it but it's secretly Scala.
Re:Elixir – Why the dot (when calling anonymous functions)? by metta2uall on Tuesday August 15, 2023 @12:57AM (#37130356)
F# is also part of the OCaml family, has a great to-JS transpiler (https://fable.io/) and F# code can also be used in .NET projects.
Re:Elixir – Why the dot (when calling anonymous functions)? by choiway on Monday August 14, 2023 @03:32PM (#37125718)
* * *
Re:Elixir – Why the dot (when calling anonymous functions)? by pjerem on Tuesday August 15, 2023 @02:10AM (#37130765)
In theory, compile time guarantees renders runtime guarantees useless as long as you don’t interact with untyped code.
Re:Elixir – Why the dot (when calling anonymous functions)? by callamdelaney on Monday August 14, 2023 @06:03PM (#37127356)
Everybody knows elixir is ass, just use Erlang.