Programming Confessions Thread
-
@Tsaukpaetra said in Programming Confessions Thread:
To my understanding, the whole point of Core was to get cross-platform compatibility , so explicitly calling out that they're not going to even fake it just demonstrates what they really intend.
Cross-platform compatibility was one goal. Being able to rev the runtime and framework classes more rapidly/thoroughly than they can the full .NET Framework was another. (The CLR enhancements that make
Span<T>
actually perform better aren't coming to the .NET Framework for the foreseeable future. Nor will the necessary enhancements to support default interface implementations and async streams in C# 8.0.)I wouldn't be surprised if all it ended up being was a collection of shims to the framework 4 libraries.
The source that they've released so far doesn't look like a collection of shims to me.
-
@dkf said in Programming Confessions Thread:
@Unperverted-Vixen said in Programming Confessions Thread:
I’m not going to be inflicting an eldritch horror upon the wider world.
That's what they all say.
That falls under the SOP:
: ... and that concludes the demo of the prototype.
: Nice. (pause with phone) Great, just announced to the world that <thing> is now available.
:
-
-
@izzion
no, it just needs another layer
-
@Luhmann An SPA?
-
@Luhmann said in Programming Confessions Thread:
@izzion
no, it just needs another layerOne Layer to rule them all, One Layer to find them, One Layer to bring them all, and in the darkness bind them.
-
@brie said in Programming Confessions Thread:
and in the darkness bind them
a.k.a. a lights-out datacenter
-
@kazitor said in TIL (about the Dark Arts of HTML):
[…] but
npm is horrible
throws an error.That's right: I have npm installed.
-
-
@boomzilla said in Programming Confessions Thread:
Open Plan offices are cheaper for businesses to have, so you just got to pull it together and take one for the owners here. I still get to complain about them.
-
@boomzilla said in Programming Confessions Thread:
I don't worry about that at all. Worry is bad for one's health.
-
@dkf ain't this a case of "If it has to happen, it will happen." All that worry is gonna make one implode.
-
Just found this in some code I wrote, it's been there a while...
success: return E_GENERIC_FAIL; failed: return E_NOERR; }
-
@stillwater said in Programming Confessions Thread:
@dkf ain't this a case of "If it has to happen, it will happen." All that worry is gonna make one implode.
Worry is my soulmate. I look forward to the implosion, though. That should be cool.
-
@Cursorkeys said in Programming Confessions Thread:
Just found this in some code I wrote, it's been there a while...
success: return E_GENERIC_FAIL; failed: return E_NOERR; }
Bonus if neither constant is equal to
0
,1
or-1
…
-
@dkf said in Programming Confessions Thread:
@Cursorkeys said in Programming Confessions Thread:
Just found this in some code I wrote, it's been there a while...
Bonus if neither constant is equal to
0
,1
or-1
…Sadly:
//The operation finished without error #define E_NOERR 0
It's now the right way round...and its callers actually check the result code.
-
@Cursorkeys said in Programming Confessions Thread:
and its callers actually check the result code.
Which change I presume brought the error to your attention in the first place. But after how much looking at other things before you realized what was going on?
-
@boomzilla said in Programming Confessions Thread:
@Cursorkeys said in Programming Confessions Thread:
and its callers actually check the result code.
Which change I presume brought the error to your attention in the first place. But after how much looking at other things before you realized what was going on?
Actually, I stumbled across that one that while fixing an entirely unrelated problem. I guess that routine has never failed...that we've noticed anyway.
-
@Cursorkeys said in Programming Confessions Thread:
Just found this in some code I wrote, it's been there a while...
success: return E_GENERIC_FAIL; failed: return E_NOERR; }
That is front-page worthy. "Hi, my name is CursorKeys, I have written WTF's..., but I have been clean for ..."
-
-
It gives me a deep satisfaction to reformat the randomly formatted queries that my cow-orker writes when she makes reports, even when I'm just making a minor substantive change to it.
-
@boomzilla said in Programming Confessions Thread:
It gives me a deep satisfaction to reformat the randomly formatted queries that my cow-orker writes when she makes reports, even when I'm just making a minor substantive change to it.
Filed under: code porn
-
Just fixed a bug. I looked and found we didn't have any automated tests covering any of this page's code. Shit. Do I really need to? OK, fine...
Wrote a simple test...found a bug (by the DB arbitrarily finding a case I hadn't considered).
-
-
@izzion related: I just added a message this morning to a configuration file but when I tested it in the application it didn't appear. Turns out I didn't hit save in the editor before launching it.
-
@izzion Or you're hitting the wrong make target. Or not all windows are looking at the same dev VM. Happens to all of us.
-
@PleegWat
Or you are hitting return/F5/"whatever execution key" on the wrong keyboard. Happened to me yesterday, with 3 keyboards in front of me and was wondering why the return key is not working on the terminal.
-
I temporarily lost sanity.
I opened a project, asked my IDE for sanity, and it was not found.
I had accidentally opened a different checkout, before I had implemented the sanity check I was searching for.
-
I needed to plot a bunch of data (just draw a line through
(x, y)
pairs, nothing complex). I also needed to get the plot in memory as SVG (not in a file or on screen) to send over network later. I also needed to do that in C++. MSVC++10 support is also a requirement (while I want the code to work on anything POSIX).As a result, I now have a function that uses
tmpnam
(retrying untilopen(... O_CREAT|O_EXCL...)
succeeds1, so it wouldn't trip on an already existing file... but other programs that don't do the check might still break) and gives the resulting name toplplot
. It works, but the linker is angry at me2:utils.cpp:(.text+0x48): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
I have briefly considered piping commands to
gnuplot
and reading the SVG from itsstdout
, but that sounds even crazier to implement in a cross-platform way.1 Or the WinAPI equivalent,
GetTempFileName
, that does the check by itself.2 On POSIX side of the code.
-
@aitap If you're wanting to output svg, and you just want to draw a single path, wouldn't it be simpler to generate the svg directly?
-
@PleegWat said in Programming Confessions Thread:
just want to draw a single path
I would also like X and Y axes with ticks and labels.
I had had this idea and had initially discarded it as "too much to write", but now that I tried it, so far it has been fun. We'll see if it's still fun by the time I have numeric tickmarks.
Thank you!
-
@aitap said in Programming Confessions Thread:
better use `mkstemp'
Fortunately, it's actually pretty easy to use. In your case (which is strewn with race conditions, but they only matter when there's a malicious actor actually about) you just need to remember to close the file handle. And you need to do a little more work to build the template string, which is the annoying (but not at all difficult) bit.
-
@dkf said in Programming Confessions Thread:
@aitap said in Programming Confessions Thread:
better use `mkstemp'
Fortunately, it's actually pretty easy to use. In your case (which is strewn with race conditions, but they only matter when there's a malicious actor actually about) you just need to remember to close the file handle.
I remember a part of my code that does that, and that I wrote about it in a thread here (can't remember where, nor when), but it could as well go in this thread.
Someone wrote the code initially on Linux, properly closing the file descriptor afterwards, then years later I ported the code later to Windows and thus replaced
mkstemp
by_mktemp_s
(in an#ifdef
), which works in exactly the same way (using the same template string format)... except that it returns an error code, not a file descriptor (and you don't need to close anything).But I did not see that difference initially and still
close
'd whatever the function returned, which caused a subtle bug that literally took us years to find! It was closing the descriptor corresponding to the error code, usually 0 when it works, so it closed the descriptor forstdin
, which worked fine the first time (the program never reads anything fromstdin
, so it didn't matter that it was closed), but crashed the second time we went through that function...
-
Oh, and another one from yesterday: I was fixing a bug caused by some data being written in the wrong order in a file by a first process, so when that file was read by a second process and assumed another order, things went wrong.
So I track down the problem in the second process, see that the wrong results come from the order in the file being wrong, track back where the file is written in the first process, fix that first process, and proceed to test by re-running... the second process only!
The worst part is that it took me a couple of hours before understanding that I needed to re-run the first process to re-generate the file, not the second one...
-
@dkf I had assumed that plplot API only deals in terms of file names. Your post made me consider calling
tmpfile
and manually replacingFILE *OutFile
in thePLStream
structure (assuming there was a way to get direct access to it).But all that hackery is not required. (The function is just not listed among the frequently used ones, which is why I missed it the first few times.) So yes, now that I know that the API I want exists, I'll use
tmpfile
, andplplot
will even close the stream for me.This is definietly my fault for not finding the function.
ETA: wait, no,
tmpfile
doesn't work on Windows because it tries to create the temp file in the root directory of the drive and fails, not having access. To create a temporary file in a directory other than the root, use tmpnam or tempnam in conjunction with fopen. Why, Microsoft, why?!
-
@dcon said in Classic Programmer Paintings:
@remi said in Classic Programmer Paintings:
@boomzilla Alternative title:
This is my code. Try to change even a single space and I'll kill you. (or: the average programmer at work)
I worked with someone like that once. I made a bug fix, resolved it. They reverted it.
Confession: Every week, I go through the history of the modules I've written to find out whether someone has done something obviously stupid. And yes, I have trust issues.
(I would never revert any commits, though, I just open tickets and bitch at people for not letting me review their changes.)
-
@dfdub said in Programming Confessions Thread:
Every week, I go through the history of the modules I've written to find out whether someone has done something obviously stupid.
I'd do that except I'm afraid of finding that the idiot doing that obviously stupid stuff was me a few months ago…
-
@dkf That's why I only look at my co-workers' commits.
-
@dfdub said in Programming Confessions Thread:
(I would never revert any commits, though, I just open tickets and bitch at people for not letting me review their changes.)
The passive-aggressive way. Even better.
(I'm just joking, don't take it badly!)
-
-
I feel dirty...
xinput map-to-output `xinput | grep "Advanced Silicon S.A. CoolTouch" | cut -f 2 | cut -d = -f 2` DP-1.2
Have to fix the touchscreen or Ubuntu maps the touch surface of that monitor to the entire 3 display desktop. And it doesn't persist across reboots (didn't test logins - I simply put it in my startup programs)
-
I wrote a DllMain that checks the process name during DLL attach/detach events, to figure out who's using this library and change behavior depending on the result.
-
@dcon said in Programming Confessions Thread:
I feel dirty...
xinput map-to-output `xinput | grep "Advanced Silicon S.A. CoolTouch" | cut -f 2 | cut -d = -f 2` DP-1.2
Have to fix the touchscreen or Ubuntu maps the touch surface of that monitor to the entire 3 display desktop. And it doesn't persist across reboots (didn't test logins - I simply put it in my startup programs)
Forgot to update this... I have to re-run that after simply locking the screen. Oh, and the name (DP-1.2) may not be the same... But that rarely changes, so that's not so bad.
-
Status: Blatantly stole someone's code and modified it to my needs...
#!/usr/local/bin/python import requests authdata = ('root','thePasswordGoesHere') #get vm list r = requests.get('http://localhost/api/v2.0/vm',auth=authdata) for vm in r.json(): if vm['autostart'] == True and vm['status']['state'] != 'RUNNING': print('Starting {}'.format(vm['name'])) requests.post('http://localhost/api/v2.0/vm/id/{}/start'.format(vm['id']), auth=authdata)
Set it as a cron job with crossed fingers, and hoping it works the first time (I'm not very well versed in python).
Edit: Lo! It doth work!
(That the
tap1
interface came up indicates that the VM was started)
-
@Tsaukpaetra said in Programming Confessions Thread:
Blatantly stole someone's code and modified it to my needs
I don't see anything special about this.
-
@Zecc said in Programming Confessions Thread:
@Tsaukpaetra said in Programming Confessions Thread:
Blatantly stole someone's code and modified it to my needs
I don't see anything special about this.
It's not special. Other than I'm not versed in python.
I'm just confessing my theft.
-
@Tsaukpaetra It's not theft if it's from StackOverflow, then it is merely inappropriate.
-
@JBert said in Programming Confessions Thread:
@Tsaukpaetra It's not theft if it's from StackOverflow, then it is merely inappropriate.
It's StackOverflow Piracy!
-
Crime: I thought I'd added full backwards support for a mixed installation of ProductV2 and ProductV3. ProductV3 has been successfully used as a Master for several ProductV2 Slaves, and we've even sold a couple pieces of ProductV3 as replacement Slaves to a ProductV2 network.
Then I get a call from the field today. The new installation of 3pc ProductV3 to an existing ProductV2 network produces "Device not found" from the V2 Master. I start tracing the communication code on a V3 on my desk:
Uh-huh... Uh-huh... ... WTF?:
static void LegacyV2StatusQueryHandle(struct netbuf* pNetBuf) { // TODO: Implement this to add support for acting as an slave for a V2 Master. netbuf_delete(pNetBuf); }
Oh f******. But how? I know we've sold at least one of these already.
Field technician: Well, they do seem to follow the general state signaling.
Right. General state signaling. Done in UDP broadcast, and the format was kept the same from V2 to V3 specifically for interoperability. Yes, it would seem to work. Except you're not going to get any alarms when it fails.
And before anyone asks why I didn't keep the whole message structure the same between V2 and V3, here's how V2 did status messaging (paraphrased):
class DeviceStatus { [...] const char* statusStrPtr; [...] } [...] void RespondToStatusQuery(char* pTxBuffer) { memcpy(pTxBuffer, &status, sizeof(DeviceStatus)); }
Yes, that's C++. Obviously, all optimization had to be turned off to keep the class structure binary-compatible between purpose-compiled versions.
I replaced most of this UDP object-sending with human-readable values over HTTP GET for V3.
Edit: removed identifiable part from snippet
Edit2: bolded first word
-
@acrow said in Programming Confessions Thread:
I replaced most of this UDP object-sending with human-readable values over HTTP GET for V3.
I wish I could do that in our code. Not a chance though: no room for TCP (let alone HTTP) on one end of the comms.