Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

271–280 of 539 posts

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

#271
post #259
post #9

Earlier quoted context omitted.

I think you can also do the second in Go with named returns, e.g. func sum(nums []int) (result int) { for _, n := range nums { result += n } } No clue if it's an idiomatic usage, and named returns always felt a little too magic for me.

you can do func sum(nums []int) (result int) { for _, n := range nums { result += n } return } and it will work same as if you would do return result As for omitting return entirely I hated it in every language where I saw it. It just feels wrong to not have return in functions that return stuff

I think missing `return` works if the language is designed around everything being expressions, so the function is just written as a single expression. I agree that in procedural type paradigms I like having the `return` keyword over things like "return the result of the last expression".

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

#272

I have long wondered why Ruby's symbols aren't in every language.

Because in most languages they're not useful. Symbols are solutions to problems, some of which are: 1. mutable strings (ruby) 2. and / or expensive strings (erlang, also non-global) If you have immutable "dense" strings and interning, and you automatically intern program symbols (identifiers, string literals, etc...) then symbols give you very little. And then there's the slightly brain damaged like javascript, where…

As the article covers, they are nice syntactically, regardless of those performance considerations. They fill a niche that in my experience actually turns out to be more common than string literals (though less common than strings as actual textual data).

I haven't written ruby (or any lisps) for awhile, and I miss symbols.

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

#274

I have long wondered why Ruby's symbols aren't in every language.

Personally, I found Ruby's symbols to be a source of bugs because they can easily get mixed up with strings. The article gives the example of dict[:employee_id]. But what happens if you serialize "dict" as JSON, then parse it again? The symbol :employee_id will be silently converted to "employee_id", which is treated as a different dict key from :employee_id. I found it was easy to lose track of whether a given dicti…

Always serialize the keys back to symbols.

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

#279
post #126

Earlier quoted context omitted.

Okay, that would confuse me. Looks very similar and easy to overlook.

Syntax highlighting can help with distinctions like that. You might prefer Nim's visually distinct "let" for immutable, "var" for mutable. "const" is also available and means resolved to constant at compile time, similar to Zig's "comptime".

it hurts that `let`, `var`, and `const` are all used in JS and mean completely different things. `let` even means the exact opposite

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

#280

> Frink has special syntax for date values. You can write # 2001-08-12 # to mean the date 2001-08-12 Frink? Frink ? This Visual Basic erasure can not stand. The #-delimited date literal syntax has been found all over the VB family: Visual Basic, VBA, VBScript, and it persists to this day in Visual Basic .NET. Of course, being a VB syntax, it's completely cursed. You can put # 01/05/2023 # in a VB file, and what date…

We don't have to follow locale, we could just force ISO 8601 and there won't be any ambiguity.
Post reply on HN