I would definitely not do nearly as well on jsdate.wtf. I really still think JS has the greater WTFs.
There definitely are some more odd / confusing ones.
Is that any different than being surprised that 1 + 1 is 2 and '1' + '1' is '11'?
>>> f"{'42':<10}"
'42 '
>>> f"{42:<10}"
'42 '
>>> f"{None:<10}"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported format string passed to NoneType.__format__
(Or any other type. What can be padded is quite inconsistent)This is unusual, often CS would love to have as much of whatever as we can, but mathematics says no that's literally or practically impossible - but here both none and lots are awful and shouldn't be permitted.
One option, which Python and C# both picked is, well, leave it to taste. You can write sixteen pages of layered expressions in the uncommented interpolated string and it'll work, but your colleagues will curse your name and plot your destruction. Or at least you'll fail code review if you enforce such things.
Another option, in standard C++ 23 today for example, is refuse to take even the first step. You can have rich formatting, but standard C++ does not provide interpolation at all, if you want to format six parameters then pass them as parameters.
I'm happy with Rust's "Only a tiny bit of interpolation" where you can interpolate only identifiers, not any other expressions, but that's definitely more interpolation than some will be happy with, yet of course in some cases it's not quite enough.
What does this have to do with either topic?
Not saying I agree, but was definitely expecting that to be the main topic of discussion here...
Hell is paved with good will I guess. Probably Justine should update https://justine.lol/lex/
C'mon, every language has quirks.
I always use a reference when doing anything non-trivial with format strings of any kind and this quiz confirmed I should keep doing that.
Also I've been using Python professionally for over a decade but TIL about the Ellipsis object.
>>> '{:{}{}}'.format('m', 'o<2', 3)
'moooooooooooooooooooooo'
it's cool that half of those features are there. it's not cool that half the devs that read the thing after creation are going to have to look up the f string features.
>>> foo='bar'; print(f"{foo=}")
foo='bar'
Wow, never knew you could do that.print("foo", foo)
The = support was added in Python 3.8: https://docs.python.org/3/whatsnew/3.8.html#f-strings-suppor...
I'd prefer writing C# if I had the Linux interaction libs Python has. I'm too dumb to write syscall wrappers
It'd be better to just let people implement their own function that prints a subset of locals(), or provide a standard function that does the same.
F-strings are great, but trying to remember the minute differences between string interpolation, old-style formatting with %, and new-style formatting with .format(), is sort of a headache, and there's cases where it's unavoidable to switch between them with some regularity (custom __format__ methods, templating strings, logging, etc). It's great that there's ergonomic new ways of doing things, which makes it all the more frustrating to regularly have to revert to older, less polished solutions.
And is there a way to link to a specific question?
https://docs.python.org/3/library/operator.html#mapping-oper...
I have so much Python to learn, I scored 10/26
Glad this is nowhere near Wat [2], though.
underdeserver•3h ago
zahlman•3h ago
Disposal8433•3h ago
And for regex you have this in some languages: https://docs.python.org/3/library/re.html#re.X
cluckindan•1h ago
elteto•3h ago