|
Harik posted:I'm well aware. It's only c++11 in that they're abusing the new features 11 brought. Are there good examples of operator "", or is it just there to be a lurking horror? Well, a trivial example would be your own bespoke artisanal string class. Saves on the macros. The builder pattern isn't too bad to use, but it's a huge pain in the rear end to implement.
|
# ? May 20, 2015 10:13 |
|
|
# ? May 17, 2024 18:12 |
|
Harik posted:I ran across this when looking up the named arguments pattern in C++, this is the C++11 way: I can't really make out what's the boilerplate from the implementation of the the actual class, but if that does what I think it is doing (it autogenerates setter methods that return the object based on the class members), that snippet is pretty cool, IMO. Besides, I don't think the Builder pattern is that bad since the successive methods This thing is at least better than doing the pattern in Java.
|
# ? May 20, 2015 14:12 |
|
Dessert Rose posted:Well, a trivial example would be your own bespoke artisanal string class. Saves on the macros. Other than strings the motivating use-case is for numeric units. With C++14 you can do things like 5s + 200ms and get the expected result.
|
# ? May 20, 2015 16:07 |
|
LeftistMuslimObama posted:One of our internal tools is basically a wrapper around a keypass database to launch sessions in all our internal unix environments. I just discovered that it can't handle passwords containing spaces unless you surround your password with quotes. So, if my password is Pass Word, I have to enter "Pass Word" in the application to be able to connect to my environment. The developer has chosen not to put the code into any of the SVN repositories (a horror in itself), so I can't find the offending code, but I can only assume that he's not escaping the password before passing it to PuTTY as an argument, because the bug doesn't happen with another terminal emulator that is launched via RPC rather than invoked via the system. Managed to track down the source for this. Sure enough, the code was (slightly psuedo'd anonymized): C# code:
Always escape your strings kids! It's fortunate that there's not really any putty arguments that could be destructive if your password had a space with a putty argument after in it.
|
# ? May 20, 2015 16:20 |
|
LeftistMuslimObama posted:Managed to track down the source for this. Sure enough, the code was (slightly psuedo'd anonymized): Is there something particularly wrong with using systems hungarian in this context? (I get that it is C# code but still...)
|
# ? May 20, 2015 16:40 |
|
shodanjr_gr posted:Is there something particularly wrong with using systems hungarian in this context? (I get that it is C# code but still...) This isn't a bad example of it, but it does result in us having stuff like integers named i_m_oNumThings (to indicate that it's an int32 global object member), which is dumb-looking, and becomes dumber when someone turns it into a long to fix an overflow because then it should be l_m_oNumThings so now your "self-documenting" code is actually deceptive. We have a lot of floats/doubles out there with int prefixes too. I'm also of the opinion that given Visual Studio's wonderful intellisense can give you all of the information that hungarian tries to convey, that adding extra characters to the name of the variable that become annoying to refactor when you make changes is silly. I realize that variable naming conventions are one of those Internet Strong Opinions things though.
|
# ? May 20, 2015 17:16 |
|
LeftistMuslimObama posted:This isn't a bad example of it, but it does result in us having stuff like integers named i_m_oNumThings (to indicate that it's an int32 global object member), which is dumb-looking, and becomes dumber when someone turns it into a long to fix an overflow because then it should be l_m_oNumThings so now your "self-documenting" code is actually deceptive. We have a lot of floats/doubles out there with int prefixes too. Yeah but that's pretty standard Hungarian notation criticism right? quote:I'm also of the opinion that given Visual Studio's wonderful intellisense can give you all of the information that hungarian tries to convey, that adding extra characters to the name of the variable that become annoying to refactor when you make changes is silly. I realize that variable naming conventions are one of those Internet Strong Opinions things though. I've seen Hungarian used in very large systems projects. Part of it was probably inertia (the software that I worked on started development in the 90s). I'm pretty sure the other part of it was that there was no decent code-completion/code-sense software that could properly parse the source tree without exploding (circa 2012 at least). Honestly, if you have a decent code review/code standards culture, stale hungarian names are not a problem imo.
|
# ? May 20, 2015 17:25 |
|
shodanjr_gr posted:Yeah but that's pretty standard Hungarian notation criticism right? Yeah, all of our code goes through two rounds of review if it's code we're releasing. In that sense, Hungarian is actually the bane of my existence because 90% of the time my code gets bounced back to me out of code review it's because I forgot to put hungarian prefixes on my variables instead of any functional problems. To me, it's a distraction to be coding and then need to pause and think "what's the right prefix for this?", but I recognize that other people find it useful and for all intents and purposes I'm outvoted on this one. We don't use hungarian on our MUMPS code (because MUMPS has no types). But we do use it on our JavaScript for some reason? I guess to indicate how you're expecting the variable to be used.
|
# ? May 20, 2015 17:32 |
i_m_o it might make sense to use Hungarian notation in a duck-typed language, just to make it clear whether your number parser returns 2 or '2'. That said, I've never used it for that.
|
|
# ? May 20, 2015 18:28 |
|
xzzy posted:X window managers are a coding horror in a category of their own, there's been more from scratch "minimalist" implementations that slowly turn into bloated monsters than any other software type. I don't think you understand how difficult ICCCM compliance is in practice.
|
# ? May 20, 2015 19:01 |
|
It's not the compliance that's a coding horror. It's the legions of wet behind the ears programmers firing up their own project with broad proclamations how THIS TIME things will be different, I mean it guys! Before Linux settled on Gnome and KDE window managers were popping up like weeds.
|
# ? May 20, 2015 19:38 |
|
Suspicious Dish posted:I don't think you understand quote:In summary, ICCCM is a technological disaster: a toxic waste dump of broken protocols, backward compatibility nightmares, complex nonsolutions to obsolete nonproblems, a twisted mass of scabs and scar tissue intended to cover up the moral and intellectual depravity of the industry's standard naked emperor.
|
# ? May 20, 2015 19:55 |
|
Not too long ago I was trying to see if I could change the default keybinds for switching from X to a tty session from Ctrl-Alt-F# to ALT-F#. After two or three days of xmodmap and xorg.conf and XKB the answer was "I don't know but gently caress X."
|
# ? May 20, 2015 20:05 |
|
Might as well link the whole thing
|
# ? May 20, 2015 20:10 |
|
To be fair it was the 80's or maybe even the 70's and we still had leaded gasoline and lead paint back then.
|
# ? May 20, 2015 23:54 |
|
Here's a little good ol' ruby. The question posed was: quote:Question: We have 4 bottles of 1 ltr, 5 ltr, 7 ltr and 10 ltr. And we can use them with their full quantity only. The reply was: code:
|
# ? May 21, 2015 04:59 |
|
Pavlov posted:Not too long ago I was trying to see if I could change the default keybinds for switching from X to a tty session from Ctrl-Alt-F# to ALT-F#. After two or three days of xmodmap and xorg.conf and XKB the answer was "I don't know but gently caress X." If you're still curious, edit /usr/share/X11/xkb/symbols/srvr_ctrl and change type="CTRL+ALT", to type="CTRL", for all of the VT bindings.
|
# ? May 21, 2015 05:38 |
|
For however bad X11 is, lmao at anybody thinking NeWS is any better. NeWS involved people writing custom PostScript scripts to shove inside a giant rear end display server, get access to the entire global namespace, even do filesystem and network operations. Not to mention that they added a way to load NeWS at runtime from an untrusted source. So you could just randomly pwn some machines on your network by sending them malicious PostScript scripts that were self-replicating and inserted them into your system at boot.
|
# ? May 21, 2015 05:42 |
|
Suspicious Dish posted:If you're still curious, edit /usr/share/X11/xkb/symbols/srvr_ctrl and change type="CTRL+ALT", to type="CTRL", for all of the VT bindings. drat, is that where it is? Then why do the xmodmap entries for the function keys have a column that specifically throws a VT keysym? I'll be honest the documentation for some of this X11 stuff is all over the loving place.
|
# ? May 21, 2015 05:58 |
|
xmodmap modifies legacy X11 keymaps through the ChangeKeyboardMapping protocol request. Those keymaps are legacy and were eventually replaced with XKB over time.
|
# ? May 21, 2015 06:44 |
|
Zibidibodel posted:Here's a little good ol' ruby. I've been looking at this for five minutes and I still can't figure out what's supposed to be horrific about it.
|
# ? May 21, 2015 06:50 |
|
sarehu posted:To be fair it was the 80's or maybe even the 70's and we still had leaded gasoline and lead paint back then. That's actually a really good explanation for what happened to X.
|
# ? May 21, 2015 06:51 |
|
GrumpyDoctor posted:I've been looking at this for five minutes and I still can't figure out what's supposed to be horrific about it. Style and structure aside, try that algorithm on 29.
|
# ? May 21, 2015 07:55 |
|
NihilCredo posted:Style and structure aside, try that algorithm on 29. Ah, lookie there. The good old change-making problem.
|
# ? May 21, 2015 09:05 |
|
I mean, the algorithm is wrong, but that's not a completely ridiculous implementation of the algorithm. If it used a foreach loop instead of the each method, you probably wouldn't think twice about it.
|
# ? May 21, 2015 09:50 |
|
Suspicious Dish posted:For however bad X11 is, lmao at anybody thinking NeWS is any better. NeWS involved people writing custom PostScript scripts to shove inside a giant rear end display server, get access to the entire global namespace, even do filesystem and network operations. Not to mention that they added a way to load NeWS at runtime from an untrusted source. So you could just randomly pwn some machines on your network by sending them malicious PostScript scripts that were self-replicating and inserted them into your system at boot. That was a different time though, back in the mid-80s when telnet and rsh were considered just fine for example despite sending passwords in cleartext over the wire, everyone ran fingerd, etc, etc. Back in the days before ubiquitous internet access to everything people didn't generally worry so much about security.
|
# ? May 21, 2015 19:34 |
|
Suspicious Dish posted:If you're still curious, edit /usr/share/X11/xkb/symbols/srvr_ctrl and change type="CTRL+ALT", to type="CTRL", for all of the VT bindings. Ok I actually got around to trying this, and this is wrong. CTRL doesn't look to be a pre-defined type (neither is ALT). I fiddled around a bit, and it seems to do what I want if I instead use type="PC_ALT_LEVEL2" and the form [ F1, XF86_Switch_VT_1 ] for my symbols. Thanks for pointing me in the right direction though.
|
# ? May 21, 2015 21:23 |
|
Co-worker: I want to generate a bunch of unique ids, but I want them to appear to be random. I was thinking of using a UUID loinburger: How many ids do you want to generate? Co-worker: At most a hundred million loinburger: Okay, that seems reasonable, you're not likely to get a collision if you use a UUID with that many ids Co-worker: The problem is that the UUIDs take up 128 bits, so I was going to truncate them down to 32 bits in order to save memory loinburger: Don't do that, you're pretty much guaranteed to get collisions with a hundred million ids and a 32-bit hash Co-worker: But the hash is 128 bits loinburger: No, the hash is 32 bits - you're truncating the UUID down to 32 bits, so you have at most 2^32 bit permutations Co-worker: But... the hash is 128 bits After a few more minutes of this he agreed that his 32-bit hash was a 32-bit hash, so crisis averted (I don't know what he's using these ids for, but I'm assuming that it would be a Bad Thing if he wound up with a shitton of repeats). I suggested that he look into non-repeating random number generators if he wanted to save 96 bits per id / eliminate the unlikely chance that he'd generate two identical UUIDs out of a hundred million ids
|
# ? May 21, 2015 21:45 |
|
loinburger posted:eliminate the unlikely chance that he'd generate two identical UUIDs out of a hundred million ids Heat death of the universe.
|
# ? May 21, 2015 21:53 |
|
Why is 128 bits a problem but 32 bits is not? Is the 4x space factor that serious of a limitation? I'm guessing 128 bits just "seems too big."
|
# ? May 21, 2015 21:55 |
|
ExcessBLarg! posted:Why is 128 bits a problem but 32 bits is not? Is the 4x space factor that serious of a limitation? Well, if you're generating 1e8 of them then it's a third of a gigabyte difference, which could be a meaningful thing for some applications.
|
# ? May 21, 2015 21:56 |
|
ExcessBLarg! posted:Why is 128 bits a problem but 32 bits is not? Is the 4x space factor that serious of a limitation? Well a hundred million 128bit keys is about 1.5 gigabytes. That's not insignificant if you can avoid it. HappyHippo fucked around with this message at 22:03 on May 21, 2015 |
# ? May 21, 2015 21:57 |
|
One of us has the math off by a factor.
|
# ? May 21, 2015 22:00 |
|
Subjunctive posted:One of us has the math off by a factor. I think it might be both of us? I corrected mine, hopefully.
|
# ? May 21, 2015 22:04 |
|
He's probably using them as keys in Redis, in which case the memory savings would be significant. I have no idea why he can't just use a counter i.e. why the keys have to be random-looking (he indicated that he didn't want random keys, he just wanted them to "appear" to be random - otherwise I wouldn't have directed him to the article on non-repeating random number generators, because they're probably pretty lovely in terms of randomness)
|
# ? May 21, 2015 22:06 |
|
Well if each 128bit code = 128 bits of memory = 100million = 1.5 gigabyte, the 32 bit code is roughly a third of a gigabyte. The difference would be ~1.125 gigabyte. One of you was talking about total size, the other about the difference.
|
# ? May 21, 2015 22:09 |
|
HappyHippo posted:I think it might be both of us? I corrected mine, hopefully. Yes, quite. I'll leave mine for future shame.
|
# ? May 21, 2015 22:13 |
|
rjmccall posted:I mean, the algorithm is wrong, but that's not a completely ridiculous implementation of the algorithm. If it used a foreach loop instead of the each method, you probably wouldn't think twice about it. Yeah this is what I meant. Wrong <> a horror, in my book. And is that unidiomatic for Ruby? (Honestly asking, I'm not a Ruby dev. It didn't jump out as weird to me.)
|
# ? May 21, 2015 22:21 |
|
I'm not sure there's a truly idiomatic way to write that loop in Ruby, although this would be familiar to most:code:
|
# ? May 21, 2015 22:49 |
|
|
# ? May 17, 2024 18:12 |
|
How would you duplicate the functionality of JavaScript's escape function in Objective-C? If your answer involves finding out what the escape function does, and writing the ~10 lines to do that in Objective-C, then you're a fool. The correct answer is: transform the string to a JS string literal, then create a webview and use it to run a script that calls the escape function on that literal.
|
# ? May 21, 2015 23:07 |