Programming Confessions Thread
-
@Gribnit said in Programming Confessions Thread:
@Gribnit holy shit, we have programmers here?
I heard some of them even know what an FPGA is
-
@Zecc said in Programming Confessions Thread:
@Gribnit I'm only an amateurgrammer.
But a professionalcrastinator?
-
@blakeyrat said in Programming Confessions Thread:
That's not the point of the thread. Post in the "I LOVE RESHARPER AND HERE'S WHY!!!" thread so I can ignore it.
I miss Blaket sometimes. You sometimes think the impressions of him are exaggerations until you stumble over one of his outbursts.
-
@DogsB said in Programming Confessions Thread:
@blakeyrat said in Programming Confessions Thread:
That's not the point of the thread. Post in the "I LOVE RESHARPER AND HERE'S WHY!!!" thread so I can ignore it.
I miss Blaket sometimes. You sometimes think the impressions of him are exaggerations until you stumble over one of his outbursts.
I gave up on interacting with him. And I was always faintly sad when I agreed with what he said, because he's so terrible at saying it.
-
@loopback0 said in Programming Confessions Thread:
@Gribnit said in Programming Confessions Thread:
@Gribnit holy shit, we have programmers here?
I heard some of them even know what an FPGA is
Yeah but even when golfing, furries are gross.
-
@loopback0 said in Programming Confessions Thread:
@Gribnit said in Programming Confessions Thread:
@Gribnit holy shit, we have programmers here?
I heard some of them even know what an FPGA is
-
@loopback0 said in Programming Confessions Thread:
@Gribnit said in Programming Confessions Thread:
@Gribnit holy shit, we have programmers here?
I heard some of them even know what an FPGA is
Full prosthetic genital anatomy?
-
@Gribnit wash your mouth out, we don’t tolerate that kind of language here.
-
@Arantor the
L
word, right, sorry.
-
There are
Foo
s and in some (fairly uncommon) cases they may belong to variousFooGroup
s.I glanced at it and thought "oh there is an easy way to get all
FooGroup
and to ask each one for all itsFoo
, but there isn't any way to directly get theFooGroup
to which a givenFoo
belongs." No big deal, I wrote a utility function to do that reverse mapping, aware that it's not very efficient but given where I needed it, not a problem. A bit tricky for other reasons, so the function is a bit beefy.And then I actually read
Foo
's documentation, and a saw a nice and clearly indicatedFoo::get_foo_group()
function.At least I hadn't committed that code yet, so I'll be the only one to see that.
-
Written in a PR: "With enough band-aids on the problem, you eventually fix the leak by sheer weight of materials."
There's a really weird bug that only happens on a batch job that edits a widget: it keeps editing the same widget every single time it runs, even though nothing has changed. So someone patched it by making a "really, did something actually change?" test to run before making changes, but that function was broken, so now I'm fixing that "did it really change?" function.
The best solution would be to go back and fix the job so that it doesn't change things that don't need to change, but I'm just stacking band-aids on top of band-aids. It'll work fine... this time. Probably. And if it doesn't, I can slap another band-aid on top...
(I'm a wee bit overworked at the moment, so, alas, I haven't the time to diagnose it properly.)
-
@PotatoEngineer said in Programming Confessions Thread:
There's a really weird bug that only happens on a batch job that edits a widget: it keeps editing the same widget every single time it runs, even though nothing has changed.
I had a bug once on a cross-platform application where fonts in styles (but not fonts in use in the document) were being reset to the default seemingly randomly. This was only being reported on the Windows side, not the Mac. It turned out to be a combination of two things. First, we were getting the WM_FONTCHANGE message much more often than we thought, even when it appeared nothing had changed. Second, when we got it we threw out our internal list of fonts and rebuilt it instead of comparing the new list in the system with our list and adding/removing as needed.
I don't remember why it only affected styles and not the fonts in use.
-
@Parody said in Programming Confessions Thread:
rebuilt it instead of comparing the new list in the system with our list and adding/removing as needed.
From my experience, there is a glaring lack of a simple, standard function (algorithm? helper functions?) to do this part-update thing without too much work or boilerplate. I can't count the number of places where we have code that needs to do that, and it almost always goes:
: alright, let's update the list of
foo
's...
... ...
: uh, it's more work than I though, let's just replace the whole list instead. Done!
... ...
: bug reported (or application crawls slower than mounted on )
: damn, can't go for the easy solution, I'll have to do the correct one instead. Ugh.
-
@Parody said in Programming Confessions Thread:
@PotatoEngineer said in Programming Confessions Thread:
There's a really weird bug that only happens on a batch job that edits a widget: it keeps editing the same widget every single time it runs, even though nothing has changed.
I had a bug once on a cross-platform application where fonts in styles (but not fonts in use in the document) were being reset to the default seemingly randomly. This was only being reported on the Windows side, not the Mac. It turned out to be a combination of two things. First, we were getting the WM_FONTCHANGE message much more often than we thought, even when it appeared nothing had changed. Second, when we got it we threw out our internal list of fonts and rebuilt it instead of comparing the new list in the system with our list and adding/removing as needed.
I don't remember why it only affected styles and not the fonts in use.
Probably firewall shenanigans.
-
@remi said in Programming Confessions Thread:
From my experience, there is a glaring lack of a simple, standard function (algorithm? helper functions?) to do this part-update thing without too much work or boilerplate.
It wants a specific loan pattern and about nobody can seem to unass enough to write their own control structures without falling into The Swamp Of
fold
.That, or it would readily fall to an ordered set approach.
Either way, it's a human problem vs technical - "we smart-smart", you see, aren't as smart as the name implies.
-
@boomzilla said in Programming Confessions Thread:
Probably firewall shenanigans.
Thankfully, Windows 98 didn't come with one. Install all the fonts you want! Unless they aren't TrueType, then you'll need some help.
-
@Parody said in Programming Confessions Thread:
Second, when we got it we threw out our internal list of fonts and rebuilt it instead of comparing the new list in the system with our list and adding/removing as needed.
This sounds like a perfectly reasonable thing to do. Changes to installed fonts should happen so rarely that I probably wouldn't have handled that message at all, just restart the application if the installed fonts have changed. Any handling of it seems like a bonus feature, so there's nothing wrong with going for a simple solution.
-
@topspin said in Programming Confessions Thread:
probably wouldn't have handled that message at all, just restart the application if the installed fonts have changed
This is how the like of Microsoft Word does it iirc.
-
@topspin said in Programming Confessions Thread:
just
restartcrash the application if the installed fonts have changedYou know it makes sense.
-
@topspin said in Programming Confessions Thread:
@Parody said in Programming Confessions Thread:
Second, when we got it we threw out our internal list of fonts and rebuilt it instead of comparing the new list in the system with our list and adding/removing as needed.
This sounds like a perfectly reasonable thing to do.
In general yes, in our layout (desktop publishing) application no. Our users were likely to have hundreds of fonts in a font manager program and would enable/disable various sets of them to minimize the strain on system resources. Sometimes this happened automatically when opening a file.
Edit: Thinking about it some more, throwing out the font list probably had the same effect as if every font in use in any open documents had gone missing. The ones in text were being found automatically as they were added back, but the ones in styles weren't relinking. It's all about side effects.
Regardless, most of our users were on Mac so issues that were only on Windows were not a priority.
-
@PotatoEngineer said in Programming Confessions Thread:
so now I'm fixing that "did it really change?" function.
For proper band-aid duck tape solution, write a
did the "did it really change function" return the correct value
function.
-
I've been known to make and use counted references within garbage-collected languages.
Worse, I can't stand to see language control structures outside library code for some reason. Or semicolons. Kinda shirty about braces even.
Worserst, I use
null
freely and without concern. To the point of null-coalescence, even.Blurst, nothing will make me abandon mutability.
And firstly, I assume multithreading.
-
@Gribnit said in Programming Confessions Thread:
nothing will make me abandon mutability
Mutability is fine when all the places that have a reference agree that you should be mutating it in the places that you are doing so. Once references get spread more widely, mutability is a pain in the ass as it results in spooky-action-at-a-distance interactions all over the code. Not many languages have good solutions to this.
-
@Gribnit You are a Kevin-alt, aren't you?
Or worse yet: you are Kevin.
Ah, fortunately, I can exclude that: Kevin can none good english write.
-
@BernieTheBernie said in Programming Confessions Thread:
@Gribnit You are a Kevin-alt, aren't you?
Or worse yet: you are Kevin.
Ah, fortunately, I can exclude that: Kevin can none good english write.Close, but my shit tends to make sense and work.
-
@dkf said in Programming Confessions Thread:
Once references get spread more widely, mutability is a pain in the ass as it results in spooky-action-at-a-distance interactions all over the code. Not many languages have good solutions to this.
Yeah, the verb
abandon
is used precisely here. In OSGi you could isolate the mutable interface by classloader, in plain Java you can keep it default access, and you really want to control instantiation pretty tightly, since then you can set up sane reference visibility (Thread or context bound).
-
@Gribnit said in Programming Confessions Thread:
@BernieTheBernie said in Programming Confessions Thread:
@Gribnit You are a Kevin-alt, aren't you?
Or worse yet: you are Kevin.
Ah, fortunately, I can exclude that: Kevin can none good english write.Close, but my shit tends to make sense and work.
You save all your nonsense for us?
-
@boomzilla said in Programming Confessions Thread:
@Gribnit said in Programming Confessions Thread:
@BernieTheBernie said in Programming Confessions Thread:
@Gribnit You are a Kevin-alt, aren't you?
Or worse yet: you are Kevin.
Ah, fortunately, I can exclude that: Kevin can none good english write.Close, but my shit tends to make sense and work.
You save all your nonsense for us?
Compartmentalization. Yes. This is my mental catbox.
-
So there's a class
Foo
, andSomeFoo
that derives from it. I have a bug and after some digging around I realise that I just need to reimplementFoo::bar()
inSomeFoo
to change the behaviour.I then proceed to spend about 2 days debugging why that doesn't work, and why
SomeFoo::bar()
is actually never called.This morning I try again, I want to add a debug print in
SomeFoo
to showFoo::name()
(yeah, I'm down to that...)."Oh right, I can't do that directly because actually
SomeFoo
contains aFoo
but is not aFoo
so I need to writefoo()->name()
. Yeah, yeah, no problem...""Now, where was I? Ah, yes, why is
SomeFoo::bar()
not called when callingFoo::bar()
?"
-
@remi What odd type of composition over inheritance did you find here?
-
@BernieTheBernie there is a reason for it, though maybe not a very good one... IIRC ( to spend too much time checking everything), this is how it goes:
There's an third-party application that handles various types of
Foo
so in addition to that base class it also has a number ofFooDerived1
,FooDerived2
etc. Actually, there are (were) at least 3 such applications, totally different from each other but that do use the same business logic and therefore all have similar (but of course never exactly identical, but that's another issue) concepts ofFoo
.So in our own library, to try and have a single code base that works with all these applications, we have a class
FooWrapper
with correspondingFooWrapperDerived1
,FooWrapperDerived2
etc. All of our own code works on thoseFooWrapper
classes and is thus application-agnostic.Then for each application we just have to implement a way to map each
Foo
of the application to aFooWrapper
, and we can use all our code (more or less) seamlessly in that application.Now the exact way the mapping is done depends on the quirks of the applications. In the specific one I'm dealing with right now (the bug was in this mapping layer), there is a
FooMapper
class for that, and the actual work happens in a bunch ofFooMapperDerived1
,FooMapperDerived2
etc. that each derive from bothFooDerived1
andFooWrapperDerived1
(2 etc.).The
FooMapper
base class is here to factorise code and it just contains a reference to both theFoo
andFooWrapper
(since that base class is common to all types, it can't know the derived type).It works. Except when there are bugs, of course.
-
@remi too bad they got rid of interfaces.
-
Every several weeks we're forced to change our password (), and we can't just make up a password, we have to use this web app where we select a password from a list of randomly generated passwords ( ). It looks like this:
So, naturally, I wrote a program that uses Puppeteer to scrape this page for passwords, and assigns each one an "easiness" score. Basically, it looks for dictionary words, favorite words (e.g. profanity), uniform case, sequences of consecutive characters, etc. Then, when it sees a password that's memorable (e.g., contains the string "fuck") it notifies me and I can review it to see if I agree before changing it.
problems require solutions.
-
I used to be able to just set the
input value
attribute to an older password but they've signed it now with a timestamp or something so that the older values expire.
-
Status: resolved a problem by cycling an object through JSON.parse(JSON.stringify())
-
@Tsaukpaetra said in Programming Confessions Thread:
Status: resolved a problem by cycling an object through JSON.parse(JSON.stringify())
Sounds like you had pass by reference issues. If it's an object only containing primitives and built in types, you can use structuredclone(), which is faster. But that doesn't handle custom types. And neither one will preserve methods on the object.
-
@Benjamin-Hall said in Programming Confessions Thread:
pass by reference issues.
Correct! And for reasons not easily researched on mobile apparently splatting it does not work as expected or something.
I'll fix it when I'm not mobile...
-
@Tsaukpaetra said in Programming Confessions Thread:
@Benjamin-Hall said in Programming Confessions Thread:
pass by reference issues.
Correct! And for reasons not easily researched on mobile apparently splatting it does not work as expected or something.
I'll fix it when I'm not mobile...
Splatting it only provides references to the things contained. It doesn't fix the issue ever unless those things inside are strings or numbers only.
-
@Benjamin-Hall said in Programming Confessions Thread:
it only provides references to the things contained
Which is fine except...... Apparently that's not what was being... Done?
Dunno, mystery for later.
-
@Tsaukpaetra said in Programming Confessions Thread:
Status: resolved a problem by cycling an object through JSON.parse(JSON.stringify())
Hooray for JavaScript’s Object.DeepClone
-
@Tsaukpaetra said in Programming Confessions Thread:
not easily researched on mobile
That's different.
-
@izzion said in Programming Confessions Thread:
@Tsaukpaetra said in Programming Confessions Thread:
Status: resolved a problem by cycling an object through JSON.parse(JSON.stringify())
Hooray for JavaScript’s Object.DeepClone
Dangit, I learned something today. That's not why I'm here!
...that said, this is quite nice. I've been using lodash's cloneDeep, which honestly works fine, but it's nice to have an official option. It's also good to see JS finally realizing that having a standard library larger than a postage stamp is a good thing.
-
@PotatoEngineer said in Programming Confessions Thread:
@izzion said in Programming Confessions Thread:
@Tsaukpaetra said in Programming Confessions Thread:
Status: resolved a problem by cycling an object through JSON.parse(JSON.stringify())
Hooray for JavaScript’s Object.DeepClone
Dangit, I learned something today. That's not why I'm here!
...that said, this is quite nice. I've been using lodash's cloneDeep, which honestly works fine, but it's nice to have an official option. It's also good to see JS finally realizing that having a standard library larger than a postage stamp is a good thing.
You made me worried that I had somehow missed that there was actually a function named Object.DeepClone now
That said, round tripping via JSON.stringify / JSON.parse is not quite as full featured as lodash.cloneDeep - stringify/parse does not clone functions. But for data objects it's a pretty reasonable deep clone option.
as of 2022: https://code.tutsplus.com/articles/the-best-way-to-deep-copy-an-object-in-javascript--cms-39655
-
@izzion said in Programming Confessions Thread:
@PotatoEngineer said in Programming Confessions Thread:
@izzion said in Programming Confessions Thread:
@Tsaukpaetra said in Programming Confessions Thread:
Status: resolved a problem by cycling an object through JSON.parse(JSON.stringify())
Hooray for JavaScript’s Object.DeepClone
Dangit, I learned something today. That's not why I'm here!
...that said, this is quite nice. I've been using lodash's cloneDeep, which honestly works fine, but it's nice to have an official option. It's also good to see JS finally realizing that having a standard library larger than a postage stamp is a good thing.
You made me worried that I had somehow missed that there was actually a function named Object.DeepClone now
That said, round tripping via JSON.stringify / JSON.parse is not quite as full featured as lodash.cloneDeep - stringify/parse does not clone functions. But for data objects it's a pretty reasonable deep clone option.
as of 2022: https://code.tutsplus.com/articles/the-best-way-to-deep-copy-an-object-in-javascript--cms-39655
I haven't (yet) had a need to clone function instances; my most common use-case is that I have an observable-thing (via MobX) that I need a copy of, to do non-observable things with. MobX's toJS() works pretty well, and when going from local-non-observable-to-persisted-observable, _.cloneDeep() works well. So I'm cloning data structures almost every time, rather than class (function?) instances.
And yes, the function is the global structuredClone() rather than Object.CloneDeep(). I'm just happy the thing exists at all!
-
TIL that when you're doing PowerShell arrays in format
@( 'foo' 'bar' 'baz' )
that you don't need a comma to separate items (the new-line character functions the same as the comma). Obviously if you were doing them single line you would, but new-line with no commas is so nice for .psd1 module files that are being source controlled.
-
@izzion said in Programming Confessions Thread:
you don't need a comma to separate items (the new-line character functions the same as the comma)
IOW, PowerShell is bad, just like JavaScript
-
-
@izzion said in Programming Confessions Thread:
TIL that when you're doing PowerShell arrays [...] you don't need a comma to separate items (the new-line character functions the same as the comma).
What happens if you do both newlines and comma? Is PowerShell smart enough to detect that as a single separator, or literal enough to detect two separators and add a bunch of empty items in your array?
-
@remi said in Programming Confessions Thread:
@izzion said in Programming Confessions Thread:
TIL that when you're doing PowerShell arrays [...] you don't need a comma to separate items (the new-line character functions the same as the comma).
What happens if you do both newlines and comma? Is PowerShell smart enough to detect that as a single separator, or literal enough to detect two separators and add a bunch of empty items in your array?
Single separator I think. In the case where I was doing both, it was to tell it a list of files to parse or functions to export, so it at least pruned empties without choking on them
-
For the life of me, I can’t figure out how to implement a bubble sort on a subsection of a table. I need a drink or something I guess.