Programming Confessions Thread
-
@Gąska said in Programming Confessions Thread:
@Tsaukpaetra I'd argue the other way on all three counts. But you do you.
This is the confessions thread anyways, and not in a help category. 😘
-
@Tsaukpaetra did anything I said help?
So don't complain.
-
@Zerosquare said in Programming Confessions Thread:
@Tsaukpaetra: this is an embedded system. You should not be doing any dynamic memory allocation in the first place.
Cries in .NET MF
-
@Gąska said in Programming Confessions Thread:
@Tsaukpaetra did anything I said help?
So don't complain.
One doesn't need to actually help in order to be accused of attempting the same, duh. 😒 giving suggestions is a form of attempting to help, so fuck yeah I'll complain!
-
@Applied-Mediocrity said in Programming Confessions Thread:
.NET MF
-
DateTime minimumDatetime = new DateTime(2000-01-01);
In my defense, I spotted it while doing a preemptive code review.
-
@Zecc What's the problem, it looks like an effective way to ensure your code stays Y2K compatible
-
@hungrier said in Programming Confessions Thread:
What's the problem
Spoiler
new DateTime(2000-01-01) == new DateTime(1998) // 1998 ticks past 0001-01-01
-
@Zecc What's the problem, it looks like an effective way to ensure your code stays 33 minutes AD compatible
-
@hungrier Problem is this piece of code I'm writing needs to deal with all of 0001-01-01, 1753-01-01, 1900-01-01 and 1970-01-01 — plus or minus one day because of time zones — as "not specified" dates apparently.
So I'm declaring the 21st century ought to be enough for everybody.
-
@Zecc but how can you build a report of the data and put that into Excel???? How will the management know you've done this?
-
I've been looking at this for an hour. I just can't get this working. It makes no sense. The unit tests are passing. The label appears but there is no data. It's not being hit in the debugger either.
aop stuff
yup. that's being hit.
That's the tricky bit. No ideas let me get...An hour later...
Ah... I forgot to replace the old call with the new call in the aop stuff...
-
@DogsB said in Programming Confessions Thread:
aop stuff
-
Heh...my son is taking an introductory programming class as an elective. They're using python.
He mentioned that a friend helped him solve something (over text or discord or something) really easily. It was a solution that he'd kind of thought about but hadn't tried for some reason and he was kind of ing over it. I had been sitting about 10 feet from him at the time and mentioned that he had other resources he could ask.
Yeah, but I don't know how much python you'd done, dad.
Eh, not that much but I've worked with it enough and with enough other languages that I'm sure I can help you.A bit later, he's getting super frustrated so I told him to show me the problem.
Look, it works here, but if I uncomment the next line I get an error!
It was something like this (the project is some kind of "creative" thing they're doing with graphics):
Group( Polygon(1, 2, 3, 4) #Polygon(5,6,7,8) )
OK, get past the awful and misleading indentation (which was in the original!) and I'm sure everyone here will spot the problem immediately with uncommenting the second call to
Polygon
, as did I, but he'd been struggling over it for 5 or 10 minutes.It reminds me of when I mix up my java / typescript lambdas (I go back and forth between those two languages all day) and replace a
=>
for a->
or vice versa.
-
-
@PleegWat Apparently it's allowed between parentheses. :genuinely-surprised-pikachu:
-
@boomzilla said in Programming Confessions Thread:
It reminds me of when I mix up my java / typescript lambdas (I go back and forth between those two languages all day) and replace a
=>
for a->
or vice versa.Same with Java and C#. Also Java and Rust. Also Java and other JVM languages. Damn Java, it ruined Java!
-
@Gąska Java sure is a contentious language
-
@Zecc said in Programming Confessions Thread:
new DateTime(1998) // 1998 ticks past 0001-01-01
Man, such a number of ticks must suck
-
-
@Kamil-Podlesak Hope you didn't get borreliosis / Lyme disease or tick born encephalitis or what ever crap after such a massive assault.
-
@Zecc said in Programming Confessions Thread:
Must be late Friday.
for(int i = 1; i <= count; count++)
And then there's this:
for(int i = 1; 1 <= count; i++)
-
Spent some time wondering why
self.filteredOccurrences = self.allOccurrences.filter { $0.matchesFilters(activeFilters) }
was returning nothing.
And then I looked at my implementation of
matchesFilters(_:)
:func matchesFilters(_ options: [OccurrenceFilterOption]) -> Bool { return false }
Well. Yup. That's working exactly as implemented.
-
@Benjamin-Hall I spent far too much time yesterday trying to figure out why
re.sub(r"pattern", "replacement", string) # Python
wasn't doing the expected replacement, when
r"pattern"
was known to match. Finally, I realized it probably was doing the replacement, but I wasn't saving the result.For those not conversant in Python, strings are immutable, so `re.sub()` returns a modified copy of `string`. It does *not* modify it in place. I knew this. I've used it before, many times. But I did the dumb anyway.
-
Some exceedingly productive time spent today staring down the following code, with steam coming out of my nose:
using (var Os = new MemoryStream()) using (var Cs = new GZipStream(Os, CompressionLevel.Optimal)) { Cs.Write(stuff, 0, stuff.Length); return Os.ToArray(); }
I really can trip over my own shoelaces...
-
I synchronized on
String#intern()
-
@Applied-Mediocrity IDGI. Is the
return
supposed to be outside the innerusing
? That's the only thing I can think of.
-
@Gąska my C#-fu is a bit hairy but the way I interpreted it, it's opening a new stream for compression, writing things to it but returning the original stream (i.e. one not compressed and possibly not having anything in it?)
-
@Arantor
ToArray()
copies the contents ofMemoryStream
to new array. You can close the stream afterwards just fine. But can you safely copy data fromMemoryStream
immediately after issuing write to theGZipStream
without closing? That's what I'm not sure of. And the intuition says yes, but since it doesn't seem to work for @Applied-Mediocrity, I'm guessing no. Unless the problem is something else.
-
@Gąska Tada! Got to flush the compression stream. Except
GZipStream.Flush()
in .НЕТ 4.8 does fuggen nothing. It flushes when disposed instead. Tbh, that's , but I could also have googled it instead of trying to stare it down like an idiot.
-
@Applied-Mediocrity said in Programming Confessions Thread:
It flushes when disposed instead. Tbh, that's ...
... a really dickish way to discourage skipping the braces. If you hadn't wanted to avoid the indent itd'of just worked.
-
@Applied-Mediocrity if you want to get really fancy, note that the
MemoryStream
's buffer (obtained withGetBuffer()
) can be kept alive even after disposing the stream. It's just a byte array after all, regular managed array. You can avoid the unnecessary copy this way. Just remember that it will contain unknown number of garbage bytes at the end so you'll need to keep track of actual data size by other means.And if you can make a good guess about final data size (doesn't have to be accurate, it'll auto-extend if you underestimate), you can use
MemoryStream(int)
constructor to preallocate and squeeze out even more performance. Actually, you almost definitely should do it, while theGetBuffer()
thing is optional.
-
@Gąska That's probably a good idea. Getting the actual data size before it's disposed might be a wee problem, though, for exactly the same reason it didn't work in the first place
-
@Applied-Mediocrity no, not at all. It will work, 100% guaranteed. GZipStream needs flushing and that's why it needed to be disposed first. But here you get a managed byte array that will outlive its original stream thanks to GC magic. It even says so on MSDN.
Just don't take this idea to C++ land.
-
@Gąska Hey, you're right (of course)! GZipStream has
leaveOpen
, so I can get the useful data size afterwards. I would blame Friday, but I am really this... slow. Thanks.
-
@Gąska said in Programming Confessions Thread:
But can you safely copy data from
MemoryStream
immediately after issuing write to theGZipStream
without closing?No, you can't. The gzip stream needs to be finalized first. (The amount of stuff that happens on flush is wildly variable otherwise, and not to be relied upon.) This fact happens to be true whatever language you're using; it's how the gzip format itself works (assuming a vaguely sane implementation).
-
@Zecc said in Programming Confessions Thread:
I'm declaring the 21st century ought to be enough for everybody.
Don't worry, it will.
-
@Zecc said in Programming Confessions Thread:
DateTime minimumDatetime = new DateTime(2000-01-01);
In my defense, I spotted it while doing a preemptive code review.
I did the same mistake today, twice in a row, writing some scratch code to find the interval between two particular dates. >_>
-
@HardwareGeek said in Programming Confessions Thread:
@Benjamin-Hall I spent far too much time yesterday trying to figure out why
re.sub(r"pattern", "replacement", string) # Python
wasn't doing the expected replacement, when
r"pattern"
was known to match. Finally, I realized it probably was doing the replacement, but I wasn't saving the result.For those not conversant in Python, strings are immutable, so `re.sub()` returns a modified copy of `string`. It does *not* modify it in place. I knew this. I've used it before, many times. But I did the dumb anyway.There's one thing I absolutely love about Ruby: they allow punctuation in function names, and they use it intelligently. Functions that end in ? always return a boolean (i.e., isNil?), and functions ending in ! make changes to the thing they're attached to. So myArray.sort!() will change the array, but you can be certain that myArray.sort() will not (so presumably, it returns a sorted copy).
JavaScript's arrays always get me. arr.sort() does in-place editing, but arr.concat(otherArr) returns a new array.
-
@PotatoEngineer a convention I've seen (in Python and elsewhere) is that
sort
changes in-place andsorted
returns, but it doesn't seem to be applied consistently.
-
@topspin plus, it won't really work when the participle is the same as the action. What does
cut
do?
-
@remi modifies in place and returns it, consistent with Schrodinger’s laws on deterministic computing behaviours; it does both and yet neither of the expected behaviours until observed.
-
@remi said in Programming Confessions Thread:
@topspin plus, it won't really work when the participle is the same as the action. What does
cut
do?It bifurcates the red node in the tree at the specified branch.
-
@topspin using the language's tense formations does help for this, and also with distinguishing early and late evaluation. Where there's a gap, either modifier words (
doCut
/cutFrom
/cutInto
) or steal a verb ( schnitten / um... etc... ).
-
@Tsaukpaetra said in Programming Confessions Thread:
@remi said in Programming Confessions Thread:
@topspin plus, it won't really work when the participle is the same as the action. What does
cut
do?It bifurcates the red node in the tree at the specified branch.
No, it dilutes the heroin with powdered milk. Or rat poison. Randomly determined at runtime.
-
@PotatoEngineer said in Programming Confessions Thread:
@Tsaukpaetra said in Programming Confessions Thread:
@remi said in Programming Confessions Thread:
@topspin plus, it won't really work when the participle is the same as the action. What does
cut
do?It bifurcates the red node in the tree at the specified branch.
No, it dilutes the heroin with powdered milk. Or rat poison. Randomly determined at runtime.
Compile time, surely?
-
@Watson said in Programming Confessions Thread:
@PotatoEngineer said in Programming Confessions Thread:
@Tsaukpaetra said in Programming Confessions Thread:
@remi said in Programming Confessions Thread:
@topspin plus, it won't really work when the participle is the same as the action. What does
cut
do?It bifurcates the red node in the tree at the specified branch.
No, it dilutes the heroin with powdered milk. Or rat poison. Randomly determined at runtime.
Compile time, surely?
Both, technically...
-
@remi said in Programming Confessions Thread:
@topspin plus, it won't really work when the participle is the same as the action. What does
cut
do?You just use the same formation, regardless of the verb itself, so you'll have
cut
andcutted
.
-
@PotatoEngineer said in Programming Confessions Thread:
@Tsaukpaetra said in Programming Confessions Thread:
@remi said in Programming Confessions Thread:
@topspin plus, it won't really work when the participle is the same as the action. What does
cut
do?It bifurcates the red node in the tree at the specified branch.
No, it dilutes the heroin with powdered milk.
No. It puts the lotion on its skin, or else it gets the hose again.
-
@djls45 I think
corter
can help here.