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
Microfeatures I'd like to see in more languages
271–280 of 539 posts
Re: Microfeatures I'd like to see in more languages
#272I 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…
I haven't written ruby (or any lisps) for awhile, and I miss symbols.
Re: Microfeatures I'd like to see in more languages
#273I really just want every language to support operator overloading.
Re: Microfeatures I'd like to see in more languages
#274I 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…
Re: Microfeatures I'd like to see in more languages
#275Re: Microfeatures I'd like to see in more languages
#276Omitting parens in a function signature when calling with one or no arguments.
Re: Microfeatures I'd like to see in more languages
#277Re: Microfeatures I'd like to see in more languages
#278Does anyone else disagree with kebab case over snake case?
to-prove-that-snake-case-is-more-readable-but-now-that-ive-written-it-i-might-be-changing-camps
Re: Microfeatures I'd like to see in more languages
#279Earlier 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".
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…