Live data from Hacker News

Ask HN: Great programming language features, other languages should steal?

news.ycombinator.com

41–44 of 44 posts

Re: Ask HN: Great programming language features, other languages should steal?

#41

This is pretty minor but I like how in Rust you can use constructs like if-statements and match-statements as expressions. For example: let foo = if some_condition { "condition is true" } else { "condition is false" }; let bar = match x { 0 => "string", 1 => "another string", _ => "default" }; It's not super significant but I think it's an elegant syntactic feature.

Kotlin, too!

Re: Ask HN: Great programming language features, other languages should steal?

#42
Factor allows almost any special character in word (function) names. It is incredibly useful when you get the hang of it. I would love to have it in other languages.

E.g. is_prime(1234) => prime?(1234), append_inplace(l, e) => append!(l, e), array_equal(a, b) => array=(a, b), midi_to_mp3(a) => midi>mp3(a), reciprocal(a) => ^-1(a)

Lisp can do some of it but not "()" or (I think) "`';"

Re: Ask HN: Great programming language features, other languages should steal?

#43
post #42

Factor allows almost any special character in word (function) names. It is incredibly useful when you get the hang of it. I would love to have it in other languages. E.g. is_prime(1234) => prime?(1234), append_inplace(l, e) => append!(l, e), array_equal(a, b) => array=(a, b), midi_to_mp3(a) => midi>mp3(a), reciprocal(a) => ^-1(a) Lisp can do some of it but not "()" or (I think) "`';"

In Common Lisp you can use pretty much any character in a symbol name, if you escape it:

  [3]> '|(``"|
  |(``"|
  [4]> (defvar |(``"| 42)
  |(``"|
  [5]> |(``"|
  42
It's pretty dubious for code; it's useful when working with some data format that has identifiers with its own validity rules.

There is more than one way to escape: vertical bars or backslashes:

  [6]> (eq '|(``"| '\(\`\`\")
  T

Re: Ask HN: Great programming language features, other languages should steal?

#44
Kotlin Extension Functions

https://kotlinlang.org/docs/reference/extensions.html

I personally love it for when I have different data classes for different layers of the application (REST objects vs. controller level objects vs. Database objects) and need to convert between them. I simply just add an extension to one layer's data object to convert it to the other layer's type

Post reply on HN