Agree with kebab-case. > Most languages have multiline literals, but what makes the Lua version great is that the beginning and ending marks are different characters. This solves the infuriating “unnestable quotes” problem string literals have, and you don’t have to escape all your literal \s. That paragraph also uses “nestable marks”.
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.)
Microfeatures I'd like to see in more languages
251–260 of 539 posts
Re: Microfeatures I'd like to see in more languages
#252Frink? 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 it represents will depend on what locale it's.. compiled? executed? evaluated? in? Maybe? Depending on which VB dialect you're in? Good luck. Some of those languages would also accept # 01/05/23 #
And they might even agree about what century it's in.Re: Microfeatures I'd like to see in more languages
#253Earlier quoted context omitted.
I don't understand the link with parent, nor why + would be bad, besides a) because language is naive about concatenation / allocation, and b) if the language allows / doesn't differentiate between a char 'x' and an integer, bc that would result in an integer addition instead of a concatenation.
If you manipulate strings in code using "+" (string concatenation symbol) from a user input you'd be in a world of hurt where you either do a lot of regex (which is ugly and unmaintainable) or you limit the user input to known characters only (which would be a bad user experience and later on your manager would ask you to lift such constraint anyway because they want to support a new feature from now on). Therefore y…
I'm just not sure what the syntax has to do with the semantics of string concatenation.
Re: Microfeatures I'd like to see in more languages
#254With regard to strings, they give a good example in Lua, but oh boy wait until this person hears about Perl (: There's a whole section in the manual [1] for string quoting operators (qq, qw, qx, ...) In general, I feel like Perl is one of those languages that has a high amount of these "quality of life" syntactic features, and helps make it enjoyable to write, once you get over the learning curve. [1] https://perldoc…
That's actually a great point. Perl has so many syntactic sugars that it is a poster child for too much variety in ways you can write things. Making it much harder to read someone else's code.
But you give up something to get benefits in those areas. Making use of the expressive power of something like Perl is a wonderful sensation. The barriers between thought and making it happen are lower, and so you can be remarkably productive. It is also just more fun, I find, which has subtle and under-valued long-term benefits.
But yeah, agreed that comprehending someone else's Perl-fueled vision quest can be ... rough (:
Re: Microfeatures I'd like to see in more languages
#255Earlier quoted context omitted.
That's actually a great point. Perl has so many syntactic sugars that it is a poster child for too much variety in ways you can write things. Making it much harder to read someone else's code.
Perl has so much syntactic sugar it's the poster child for syntactic diabetes, really.
Re: Microfeatures I'd like to see in more languages
#256Earlier quoted context omitted.
Ruby happily allows this and I can't recall it ever being an issue. It's no more prone to errors than `x` being greater than the number of elements. > arr = ["a", "b", "c", "d", "e"] > x = -2 > arr[x] => "d"
If you intended to calculate an index and you accidentally get len(arr), you get a runtime error. But if you accidentally get -1 you silently get the last element instead. Similar to the argument about signed/unsigned indices in low level languages.
> Similar to the argument about signed/unsigned indices in low level languages.
Think that one has to do more with convenience where most of stuff uses int by default
Re: Microfeatures I'd like to see in more languages
#257Earlier quoted context omitted.
If you have two functions abracadabra(foo) and foo.abracadabra() which do different things , you should rename one of those functions tbh.
The problem is when you have the functions: Square.computeArea() Circle.computeArea() Clearly these should do different things. I suppose "computeArea(shape)" does dynamic dispatch based on the type of shape? But you're still putting every function defined on every type in your entire codebase in a global namespace. It's not obviously awful but I'd definitely be a bit nervous about it.
The problem really starts when you have
typeA.func()
typeB.func(x)
typeC.func(x=default_value)
Re: Microfeatures I'd like to see in more languages
#258Re: Microfeatures I'd like to see in more languages
#259My 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. Another one from Nim is the implicit result variable. Instead of having to do this: func sum(nums: seq[int]): int = var result = 0 for num in nums: result += num return result you just do this: func sum(nums: seq[int]): int = for num in nums: result += num It…
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.
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 stuffRe: Microfeatures I'd like to see in more languages
#260I have long wondered why Ruby's symbols aren't in every language.