Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I might do this weekly. You can discuss things you like about your favorite (or any) language, and I may appreciate them in a post!
-
I would rather use a string repeat function for that tbh. This kind of thing is what ticks me off about Python et. al. (don't get me wrong, I love Python otherwise).
-
@RememberMe I love syntax that reads like english. That's the largest reason Lua is my favorite language. It has many flaws otherwise.
But seeing "-" * 30 and getting "------------------------------" as output just is so intuitive. That's exactly what you expect. And with Python's lack of type coercion, it's not confusing or ambiguous, either -
You could do that in many (statically typed) functional languages too, you just need to overload the * operator.
(REPL link: https://bit.ly/33kz3PL) -
To add on to @finiteAutomaton’s comment here’s an overload for c++:
std::string operator*(std::string s, int n) {
std::string out = "";
while(n--) {
out += s;
}
return out;
} -
hjk10156964yFunny, this is one of the things they borrowed from Perl. Only there it is a "x" operator.
One of the uses is repeated patterns like the wake on LAN Magic packet. -
@RagingCodeChimp Kotlin is the big tits rich sister to Java. Of course it does...
This week in Programming Language appreciation: the multiplication operator in Python. You can use it on strings and arrays for incredible ease of use. For a horizontal line in a terminal?
print("-" * 30)
Very helpful, and I have used it a lot. And I miss it in other languages.
rant