Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

421–430 of 539 posts

Re: Microfeatures I'd like to see in more languages

#421
post #408

Earlier quoted context omitted.

FWIW, Raku and XPath support kebap-case. If you really mean subtraction, you have to add whitespace.

That works, but isn't necessary in Raku. As long as the right side of the hyphen does not start with an alphabetic character, you're good: my $a = 45; say $a-3; # 42

That's such a perl/raku thing, and I mean it in the best way possible.

Re: Microfeatures I'd like to see in more languages

#422

Earlier quoted context omitted.

Elixir has forward pipes, but didn't invent them. For instance Racket and Clojure have threading macros , which are more flexible as they're just macros (Clojure's `->` is equivalent to Elixir's pipe operator, but `->>` will fill in the last parameter rather than first, and `-->` lets you use a keyword to define where the parameter is inserted in each call). Haskell let anyone who wants define their own pipe operator…

The earliest I've seen |> specifically in stdlib was in F#, which still predates Elixir by several years.

It was present in SML codebases earlier than F# (it's used everywhere in the Isabelle codebase, for example, and that's where I first came across it).

Re: Microfeatures I'd like to see in more languages

#423
post #138

Earlier quoted context omitted.

Also on a function? var getDate() { return „no date“; }

No, but I think that was a good choice. In local code this is great, but in an interface contract being explicit about data type is a virtue.

But rust still allows declaring returning a trait instead of explicit types.

Re: Microfeatures I'd like to see in more languages

#425

Earlier quoted context omitted.

> 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.

Except I find the concept of state "doing something with" other state unhelpful. Why is bar working with baz and not baz working with bar? I struggle with this in Unity: Player.collect(PickUp) // this? PickUp.boost(Player) // ...or this? Instead, the code should describe the interaction between the two units of state: onCollide(Player, Pickup) If we structure our code like in the last example, it makes sense to weake…

I think which of the three is best depends on the context:

What is the code driving it?

- looping over players to update them?

- looping over objects to update them?

- some other event loop?

I actually like the third least:

The first two tell me what is happening, but the third doesn’t — I could be colliding to block motion or I could be picking up.

Re: Microfeatures I'd like to see in more languages

#426

WebGL's swizzling vector selectors.[1] Where v.x desugars as v[0], v.y as v[1]. Similarly for z and w. Also r,g,b,a. And they swizzle: v.rgb, v.xz, v.zx . So `v1.xy = v0.yx` reflects. [1] https://www.w3.org/TR/WGSL/#vector-access-expr

That applies to GLSL in general. I tried once to emulate that using C unions, but quickly realized that there's no solution for v.xz, v.xw, v.yw, etc.

You can write functions like xyz(v) and that works well enough. Even better if you have ufcs or methods.

Re: Microfeatures I'd like to see in more languages

#427

I'm partial to for-else-loops. They fit perfectly into languages with compound expression (produce a value from a break in the loop or from the else block). They don't come up that often, but when they do they're really the best solution.

I used one recently in a script and they're definitely not that readable. It always takes some time what "else" means in the context of a loop.

I feel like it would work better with a more explicit keyword, but I don't know which one. `nobreak`?

Re: Microfeatures I'd like to see in more languages

#428
post #406
post #359

Earlier quoted context omitted.

What exactly do you mean by "damned" here?

I am assuming the author is using it as one would use "wicked" (with a positive conotation)?

I don't know why teenagers insist on taking a negative work and making it positive, especially when teenagers don't like adding emphasis to words so you have no idea whether they think it's good or bad.

Not that I was completely innocent of this at that age.

/Rant.

Re: Microfeatures I'd like to see in more languages

#429

Earlier quoted context omitted.

Nestable comment syntax is also nice. At least some MLs (eg SML) has it, that I know of. Indentation-sensitivity can also solve similar problems. (Indentation does not have to exclude requiring graphic termination. A formal language can require both. Or just a helpful tool.) (Also agree with 'kebab-case', although the name is new to me and a bit weird.)

What makes C-style comments unnestable?

They are defined to be non-nestable. Any appearance of */ terminates the comment.

Re: Microfeatures I'd like to see in more languages

#430
Just to pop in on kebab case:

Prolog has a weird third thing going on. Arithmetic only happens in specific contexts. i.e.

  A is 4 - 2, % arithmetic, technically is(A,-(4,2)), A is 2
  A #= 4 - 2, % arithmetic, A is 2
  A = 4-2, % non arithmetic, A is unified with the term -(4,2) which pretty prints as 4-2
  A = -2, % non arithmetic but A is the number -2 not a term -(2).
  A = 4-2, B is 4 + A, % a weird one A is the term -(4,2) but when it gets called in the context is(B,+(4,A)) it gets treated as the arithmetic '-' and B is 6
you can also kebab-case predicate names so

  l-h-t(L,H,T) :- L = [H|T].
  
  ?- l-h-t([1,2,3,4],H,T). %works as desired
  H = 1,
  T = [2, 3, 4]. 
you can't do it with variables though.
Post reply on HN