With 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…
Microfeatures I'd like to see in more languages
261–270 of 539 posts
Re: Microfeatures I'd like to see in more languages
#262Negative array subscripts. So a[-1] means the last element of an array, a[-2] means the second last, and so on.
Re: Microfeatures I'd like to see in more languages
#263Re: Microfeatures I'd like to see in more languages
#264Negative array subscripts. So a[-1] means the last element of an array, a[-2] means the second last, and so on.
Re: Microfeatures I'd like to see in more languages
#265I'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.
Re: Microfeatures I'd like to see in more languages
#266Elixir's sigils are amazing. There are date sigils that allow you to do what the OP does: ~N[2023-01-01 12:00:00] But you can also define your own sigils to create new "custom syntax" for almost any struct. Kind of a special case of reader macros, I guess. Very convenient.
Swift has the expressibleby Type literal series of protocols for this. For example you could write an extension on Date to add initialization from a string: extension Date: ExpressibleByStringLiteral { public init(stringLiteral value: String) { // parse the string here. } } You can then do things like: let happyNewYear: Date = “2023-01-01 12:00:00” There are a protocols for all literal types. For example, you could i…
Re: Microfeatures I'd like to see in more languages
#267With 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…
qw was great. Even in Python I sometimes write: usernames = ''' foo bar baz hello world '''.split() # instead of this, which needs too many keystrokes usernames = ["foo", "bar", "baz", "hello", "world"] Interestingly, Python named tuples have similar interface for fields: # all of these are equivalent EmployeeRecord = namedtuple('EmployeeRecord', ['name', 'age', 'title']) EmployeeRecord = namedtuple('EmployeeRecord',…
Re: Microfeatures I'd like to see in more languages
#268Negative array subscripts. So a[-1] means the last element of an array, a[-2] means the second last, and so on.
While I agree, I've met people who think the idea of a negative index is completely absurd. Their brains seem to immediately reject the concept.
Re: Microfeatures I'd like to see in more languages
#269Earlier 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.
Re: Microfeatures I'd like to see in more languages
#270But one of the things I love most is how seriously they take having their Hash be enumerable. I love being able to loop through any hash as easily as you would with an array