TIL (about the Dark Arts of HTML)
-
@Zecc Next you're going to tell me that
Microsoft.VisualC
containsmalloc()
-
@Vixen said in TIL (about the Dark Arts of HTML):
care to explain?
(inb4 :shoulder_aliens: I think I know what @dkf is referring to, and I'm confident that I'll be vehemently corrected in no time if I'm wrong)
If the object you're trying to index is not the type of object you think it is, but for example a proxy to a proxy to another object which just stores away the parameters to later try and index something else entirely, it may be somewhat difficult to figure out what went wrong in that second, seemingly unrelated call. Yes, that's a situation one might encounter in complex python code, especially if it's using lots of external
librariesmodules. Welcome to the fabulous world of typing!
-
Which is, however, issue of said
@ixvedeusi said in TIL (about the Dark Arts of HTML):
typing!
and not really of the indexing syntax and usefulness of its semantics for strings. Many other languages have user-defined indexing operators that can take arbitrary parameters, but few actually make them as useful as Python.
-
..
-
Yes, Now say it faster!
-
-
@JBert said in TIL (about the Dark Arts of HTML):
@anonymous234 said in TIL (about the Dark Arts of HTML):
@ixvedeusi I wish other languages would adopt some of Python's good ideas. Real life example: had to trim a string to the first 100 characters.
Python:
text[:100]
C#:text.Substring(0, Math.Min(text.Length,100));
It's interesting that the VB.NET assemblies still have a helper for that. I don't know if you can use it from a C# program but it might raise a few eyebrows if you do. No idea why they haven't copied that one to somewhere else by now.
Library designers seem to have this idea that it's good to keep functions to a bare minimum. So if there's string.Substring, they won't add string.Left because it's "redundant".
IMO this is the opposite approach. I'd add every helper function that anyone could potentially want to use. Trim left, trim right, trim middle, everything.
Because at some point, someone is going to need them. Having them in the library makes their code more semantic, and I see no downsides if you do it right (build them on the other functions so you can still make changes to the class internals without having to change everything).
-
@anonymous234 The former extreme leads to a lot of repeated boilerplate. The latter makes it hard to tell what does this code even do/do we even use this code/how deep does the pile of wrappers go.
-
@PleegWat said in TIL (about the Dark Arts of HTML):
The latter makes it hard to tell what does this code even do/do we even use this code/how deep does the pile of wrappers go.
That's why it's better if the standard library does have the wrappers. Then at least all code in that language uses the same wrappers, so everybody has better chance of learning them. Otherwise every project will cook its own weird set.
-
Would it be a good idea if the actual implementation exposed only the minimal orthogonal set and all the helpers go in a separate helper class or classes? For one thing, someone could write a different class that met the contract of the minimal implementation and they'd get all the wrappers for free without being in doubt about which ones they need to implement themselves.
-
@Watson Modern languages have some kind of provided methods in interfaces, mixins, or extension classes, that can be used for this purpose, and where they are available and the maintainers are reasonable enough to add the helpers, they are used.
-
@Bulb said in TIL (about the Dark Arts of HTML):
Which is, however, issue of said
@ixvedeusi said in TIL (about the Dark Arts of HTML):
typing!
and not really of the indexing syntax and usefulness of its semantics for strings. Many other languages have user-defined indexing operators that can take arbitrary parameters, but few actually make them as useful as Python.
You wait until you study what Numpy can do with indexing. It is tremendously powerful, and able to hide a lot of confusion and trouble in a very short piece of code. Good luck debugging it, especially where some parts come from outside the class you're working on!
-
@Bulb said in TIL (about the Dark Arts of HTML):
@PleegWat said in TIL (about the Dark Arts of HTML):
The latter makes it hard to tell what does this code even do/do we even use this code/how deep does the pile of wrappers go.
That's why it's better if the standard library does have the wrappers. Then at least all code in that language uses the same wrappers, so everybody has better chance of learning them. Otherwise every project will cook its own weird set.
The biggest problem with that is that it increases the support load for the standard library. Standard library developers are rarely at a loose end for things to do as it is...
-
@TimeBandit said in TIL (about the Dark Arts of HTML):
@Applied-Mediocrity said in TIL (about the Dark Arts of HTML):
military engineers using explosives to clear ice is quite common thing in places where rivers tend to do that sort of thing?
In Quebec, we have a special machine to do that
That video only showed it crawling over land and hauling some ice from right to left. This one better shows these Canadian machines:
-
TIL Pat Morita's rather distinctive voice for Mr. Miyagi was actually pretty genuine. He based it on the way his stunt double talked, who was a recent immigrant from Okinawa.
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
@ixvedeusi said in TIL (about the Dark Arts of HTML):
Yeah, the addition of grid layout finally turned the common "don't use tables for layout" mantra from idealistic bullshit into actual good advice
In general, if people keep doing things a certain way instead of what you think is the "right" way despite your advice, it means their way is easier and you need to improve the "right way".
And tables are still better
-
@sockpuppet7 said in TIL (about the Dark Arts of HTML):
And tables are still better
That depends. Are they wooden?
-
Official flag of River Gee County of Liberia:
-
@Gąska said in TIL (about the Dark Arts of HTML):
Official flag of River Gee County of Liberia:
Reddit claims to have an original design sketch:
https://www.reddit.com/r/vexillology/comments/9kzx1p/the_original_flag_of_river_gee_county_liberia/
Though they also seem to indicate that the real flag still looks different than the SVG on wikipedia:
https://www.reddit.com/r/vexillology/comments/2ny7f4/flag_of_river_gee_county_liberia_looks_like_it/
-
@JBert well, I'm pretty sure the real one is the one I posted.
https://www.emansion.gov.lr/2press.php?news_id=4006&related=7&pg=sp
-
-
@topspin One of the few countries using those weird units of measurement.
-
@Zecc said in TIL (about the Dark Arts of HTML):
@topspin One of the few countries using those weird units of measurement.
It all fits together!
Filed under: except at the edges where they didn't measure correctly.
-
TIL where some of my tax money is going...
https://ec.europa.eu/eipp/desktop/en/projects/project-9401.html
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
@ixvedeusi I wish other languages would adopt some of Python's good ideas. Real life example: had to trim a string to the first 100 characters.
Python:
text[:100]
C#:text.Substring(0, Math.Min(text.Length,100));
C#:
text[..100]
Get with the times.
e: oh. Well,text[..(text.Length < 100 ? ^0 : 100)]
-
@pie_flavor what does
^0
do? Is that just a weird way to write -1?
-
@topspin Huh. Guess this is the correct thread.
To answer your question:
^0
is sugar forIndex.CreateFromEnd(0)
which I think it's an error, as based on the linked article, indexing from the end starts at 1 .
-
@Zecc The reference article you linked allows it:
^0
does not throw, but it translates to the length of the collection/enumerable it is supplied to.- Range.All is semantically equivalent to
0..^0
, and can be deconstructed to these indices.
-
Filed under: typing "reading" at the prompt bring , which isn't quite what I intended.
-
@topspin said in TIL (about the Dark Arts of HTML):
@pie_flavor what does
^0
do? Is that just a weird way to write -1?So I guess to answer your question: yes.
-
@Zecc said in TIL (about the Dark Arts of HTML):
To answer your question: ^0 is sugar for Index.CreateFromEnd(0) which I think it's an error, as based on the linked article, indexing from the end starts at 1 .
But then
^0
creates aSystem.Index
object, which is a different type than100
in the conditional operator. Can C# handle that (by automatically casting the different branches to a common type)?
-
@topspin I know that you sometimes need a cast if one of the branches is e.g. a nullable boolean and the other is a regular boolean.
Best case they thought of that and somehow made the compiler smart enough to deal with this. Worst case you might need to write it as
text[..(text.Length < 100 ? ^0 : (Index)100)]
.
-
@Zecc said in TIL (about the Dark Arts of HTML):
To answer your question: ^0 is sugar for Index.CreateFromEnd(0)
I'm happy that there's syntactic sugar, but why use this symbol?OK, I know the answer: because every other symbol was taken. And they can't use keywords like idx(0) because it might break something.
-
@anonymous234 So that you could make a face with it:
[:^0]
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
I'm happy that there's syntactic sugar, but why use this symbol?
but what about using negative numbers..?
python does that by having indexes from the end of the array count in negative numbers so
arr[1..-2]
takes the list except for the first and last element
-
@Vixen said in TIL (about the Dark Arts of HTML):
@anonymous234 said in TIL (about the Dark Arts of HTML):
I'm happy that there's syntactic sugar, but why use this symbol?
but what about using negative numbers..?
python does that by having indexes from the end of the array count in negative numbers so
arr[1..-2]
takes the list except for the first and last elementWould turn existing bugs (especially where variables are used) into undesired behavior? Places where exceptions are currently caught and handled?
-
@boomzilla said in TIL (about the Dark Arts of HTML):
Would turn existing bugs ... into undesired behavior?
Um, aren't existing bugs already undesired behavior?
-
@HardwareGeek Well yes, but if previously your code would crash with a "negative index exception" then you don't want to end up in a situation where this will suddenly run without exception but with the wrong offset selected. It might then turn out that data you've been processing over a couple of months is all rubbish, with nothing to warn you.
-
@JBert said in TIL (about the Dark Arts of HTML):
It might then turn out that data you've been processing over a couple of months is all rubbish, with nothing to warn you.
If it is real data, then it probably mostly is rubbish anyway.
-
@topspin Yes, because Index has an implicit conversion from int.
-
@Vixen said in TIL (about the Dark Arts of HTML):
@anonymous234 said in TIL (about the Dark Arts of HTML):
I'm happy that there's syntactic sugar, but why use this symbol?
but what about using negative numbers..?
python does that by having indexes from the end of the array count in negative numbers so
arr[1..-2]
takes the list except for the first and last elementThis replaces negative numbers. In C# that's
arr[1..^1]
. And the reason it's not just negatives is so that you can zero-index it with ^0 meaning the length. Also, it's not just magic range syntax as described above;System.Index
is the type that accepts hats, andarr[-1]
can't suddenly stop throwing or stuff breaks, butarr[^1]
makes total sense.
-
@pie_flavor End-relative indices make a lot of sense (even if the syntax isn't one I care for). Python's hackery to abuse negative numbers for that purpose... far worse, since they can arise accidentally in ordinary calculations.
But that's Python for you. Masses of expedient hacks that can backfire weirdly.
-
TIL Comodo changed its name to Sectigo.
-
-
@Watson said in TIL (about the Dark Arts of HTML):
@Zecc said in TIL (about the Dark Arts of HTML):
Sectigo.
Sounds like a skin condition.
Or an inner ear condition,
-
TIL (provoked by @boomzilla's post):
(via https://dictionary.cambridge.org/dictionary/english/chaser)
-
@Gąska said in TIL (about the Dark Arts of HTML):
TIL (provoked by @boomzilla's post):
(via https://dictionary.cambridge.org/dictionary/english/chaser)
Dafuq. Wouldn't it be easier to say "a differently-strong alcoholic drink from the previous"?
-
No.
-
@Tsaukpaetra UK vs. US.
I love how they're exact opposites. The question is, which one was first, and which one was a stupid joke that got out of control?
-
@Gąska In Germany the word "chaser" is only used when mixing cocktails - and stands for the non-alcoholic ingredients used to fill up the cocktail.