CodeSOD collection
-
@Tsaukpaetra said in CodeSOD collection:
Status: Mother. Fuckers.
And
PShowHistoryRecords
isprotected virtual
for extra funny , isn't it?
-
@BernieTheBernie In C++ it would be
private virtual
, but Java and C# don't allow that. It is a useful idiom … if it wasn't for the fact that the wrapper does not do anything useful.
-
@Bulb said in CodeSOD collection:
In C++ it would be
private virtual
, but Java and C# don't allow that. It is a useful idiom … if it wasn't for the fact that the wrapper does not do anything useful.What is that? Must be implemented by subclasses but cannot be called from outside? (I get that with an annotation and a static checker. I also use that approach to make sure I don't do string substitution to create SQL to run, as well as checking lock rules. Useful.)
-
@dkf Yes. The idea is that you have a public method that ensures some invariants for the class, and somewhere inside calls one or more virtual methods implementing the main logic differently for different subclasses. The wrapper method ensuring invariants makes the subclass implementation simpler, but it means the inner virtual methods should never be called directly because that could break those invariants.
It is used in the standard library iostreams module. The streambuf has private virtual methods defining the actual data sources/sinks (file, string, possibly custom ones) while the public wrappers take care of splitting the calls according to what fits in the buffer and such.
-
@Bulb Sounds like an abstract method. Does C++ have abstract?
-
@PleegWat said in CodeSOD collection:
@Bulb Sounds like an abstract method. Does C++ have abstract?
C++ has abstract, but this is completely orthogonal to abstract.
- Abstract means the subclass must implement it.
- Private virtual means the subclass may override it, but it can only be called through the wrapper in the base class.
I think that in the iostreams example, some of the private virtual methods are also abstract, but others are not and have valid default implementations.
-
OpenStreetMap has been mentioned a couple of times on WTDWTF. They use a postgres database on their backend, and have a simplicistic data model: they store key-value-pairs, and all data therein are strings.
What can go wrong?
Well, some data are numeric.
Really? Can you give an example?
Population of a village.
And since it is entered and stored as a string, let us enjoy regional formatting issues.The mailing list for mkgmap (the tool to create Garmin maps from OpenStreetMap data) just recently showed following issue:
In my style I have
place=village & population < 30 {set place=hamlet;echotags "village to hamlet"}
The following place node gets flagged up as it has been given a population of 1
population:1,350Well, these are cultural issues, aren't they?
-
@BernieTheBernie said in CodeSOD collection:
Well, these are cultural issues, aren't they?
Yes. Having numerical grouping separators in stored data is bad and they should punish the bad.
-
@BernieTheBernie said in CodeSOD collection:
OpenStreetMap has been mentioned a couple of times on WTDWTF. They use a postgres database on their backend, and have a simplicistic data model: they store key-value-pairs, and all data therein are strings.
What can go wrong?
Well, some data are numeric.
Really? Can you give an example?
Population of a village.
And since it is entered and stored as a string, let us enjoy regional formatting issues.The mailing list for mkgmap (the tool to create Garmin maps from OpenStreetMap data) just recently showed following issue:
In my style I have
place=village & population < 30 {set place=hamlet;echotags "village to hamlet"}
The following place node gets flagged up as it has been given a population of 1
population:1,350Well, these are cultural issues, aren't they?
Arguably you could put some validation logic into the database for a small set of "widely accepted" tags where the range of allowed values is defined, but that would probably open another can of worms like the fight over who defines what is or isn't allowed. But the much easier solution is to do input validation on upload, like other editors do:
In this particular case, JOSM finds the PEBKAC but iD doesn't
-
@LaoC Now set your machine's locale to
en-US
and try again...
-
@BernieTheBernie said in CodeSOD collection:
@LaoC Now set your machine's locale to
en-US
and try again...That's what it's set to anyway.
-
@LaoC this screenshot gave me eye cancer.
Let me guess, it’s Java?
-
@topspin said in CodeSOD collection:
@LaoC this screenshot gave me eye cancer.
Let me guess, it’s Java?That's what the J in JOSM stands for.
Yeah, the smudgy look is the scaling kludge to get (parts of the) 90s style GUI to not look like on a 4k monitor.
-
@LaoC said in CodeSOD collection:
the smudgy look
I as a normal example of human feel it looks just fine.
-
@Tsaukpaetra said in CodeSOD collection:
I as a normal example of human
-
@Tsaukpaetra said in CodeSOD collection:
I as a normal example of human feel it looks just fine.
You can stop pretending. The fact we are all dogs is already out
http://wibble.fbmac.net/new-study-reveals-shocking-truth-about-internet-users
Filed under: I am a cat, though
-
@Bulb said in CodeSOD collection:
we are all dogs
All my bitches will attest that I give best scritches!
-
@Tsaukpaetra said in CodeSOD collection:
@Bulb said in CodeSOD collection:
we are all dogs
All my bitches will attest that I give best scritches!
Pictured: satisfied bitch:
-
@Tsaukpaetra said in CodeSOD collection:
This just in!
Status: "Understand security tool issues" meeting concluded. I think they kinda understood the problem.
They will be removing the second configuration file (that has the unencrypted database password) from the deployment package.
It is really difficult to imagine how hard it is to comprehend that putting the key next to the lock means you have no lock.
But, I believe at least I got them to agree that maybe sending the cyphertext blob with every entry listing was a Bad Idea, even if I couldn't get them to agree that storing them all with the same key (which key is retrieved by a key-by-the-lock door) was a Bad Idea.
-
-
@Tsaukpaetra said in CodeSOD collection:
putting the key next to the lock means you have no lock.
Did they at least hide the key under the mat?
-
@HardwareGeek said in CodeSOD collection:
@Tsaukpaetra said in CodeSOD collection:
putting the key next to the lock means you have no lock.
Did they at least hide the key under the mat?
They hid a copy of the original key under the mat. But a painted copy of the original is indeed right next to the door, folded in a sticky note that reads "shhh"
-
@Tsaukpaetra said in CodeSOD collection:
@HardwareGeek said in CodeSOD collection:
@Tsaukpaetra said in CodeSOD collection:
putting the key next to the lock means you have no lock.
Did they at least hide the key under the mat?
They hid a copy of the original key under the mat. But a painted copy of the original is indeed right next to the door, folded in a sticky note that reads "shhh"
They also included the bright blinking neon arrow pointing at the sticky note, right?
-
@Tsaukpaetra said in CodeSOD collection:
It is really difficult to imagine how hard it is to comprehend that putting the key next to the lock means you have no lock.
Did you put the key below the doormat?
Of course not, because that's where you'd look first!(OTOH, remember that story by Edgar Allen Poe where a letter was put openly on a wooden table, and hence not seen?)
-
@BernieTheBernie I don’t, but I remember the heart is under the floorboards.
-
Microsoft seems to have found out why so many companies using Azure do test in production:
Use separate App Service plans for production and testing. Otherwise, if you use the same plan for production and testing, it means your tests are running on your production VMs.
-
@BernieTheBernie They run on the production VMs, but are still separate instances. For some tests that's fine. For some it's not.
Also it's complicated by the fact that slots can't run on different app service plan. Which makes sense—running on the same VMs is what enables you to swap them without interruption. But then people think hey, slots are cool, we'll use them for testing. Instead of only using them for staging.
-
This isn't the most confusing and verbose possible way to write
if (i == 0 || i == 3) { ... }
, but it isn't good.for (int i = 0; i < 6; i++) { if (i > 0 && i < 3) continue; if (i > 3) continue; // do stuff if i equals 0 or 3 }
-
@HardwareGeek That's not the worst sin. The worst sin is the for-switch pattern. That is, why the fsck is there a loop running for six iterations when four of them are then simply skipped?
-
@Bulb In the interest of anonymization, I omitted the comment that doing something useful for only two of the values of
i
is "for now". I have no idea how long that "temporary" restriction has been in place, but that's something I'm going to be changing. (By limiting it to only one.)
-
Status: Am confuzzed.
I guess the analyzer can't tell that it's returning a new object (probably)?
-
@Tsaukpaetra assuming you’re on a non-dinosaur edition of PHP, typehint the return type as a View.
-
@Arantor said in CodeSOD collection:
@Tsaukpaetra assuming you’re on a non-dinosaur edition of PHP, typehint the return type as a View.
Yeah I figured that out quickly enough, but it's kinda weird. Should have just said "Herp, I can't tell if this new object isn't
void
for some reason"
-
@Tsaukpaetra Devsense?
-
-
@Tsaukpaetra said in CodeSOD collection:
@Arantor said in CodeSOD collection:
@Tsaukpaetra assuming you’re on a non-dinosaur edition of PHP, typehint the return type as a View.
Yeah I figured that out quickly enough, but it's kinda weird. Should have just said "Herp, I can't tell if this new object isn't
void
for some reason"Well here's the wild thing; a function declared void in PHP will error out if you actually return any value. Even null.
And I mean: error out at compilation time.
<?php function myfunc(): void { return null; }
Is a compile level error:
Fatal error: A void function must not return a value (did you mean "return;" instead of "return null;"?) in /tmp/preview on line 4
-
@Arantor said in CodeSOD collection:
if you actually
This I don't actually mind so much. An explicit contract being broken is obviously wrong. But an implicit one like above probably shouldn't unless there's reason to believe the instantiation fails in a really weird way...
-
@Tsaukpaetra It actually can't. Your IDE is broken.
In PHP, a constructor can only do three things: it can only return itself, it can throw an exception or it can exit.
There is no way to return a value from a constructor that isn't explicitly an instance of the object being constructed - short of throwing an exception and catching something in the returned exception class.
-
-
@Arantor said in CodeSOD collection:
In PHP, a constructor can only do three things: it can only return itself, it can throw an exception or it can exit.
There is no way to return a value from a constructor that isn't explicitly an instance of the object being constructed - short of throwing an exception and catching something in the returned exception class.
Can it return an instance of a subclass? Or do you need all the explicit factory class stuff that infests the more OO-pattern-y end of Java coding?
-
@dkf You need the factory stuff. By the time you hit a concrete constructor you're getting an instance of that class.
-
@dkf said in CodeSOD collection:
Can it return an instance of a subclass? Or do you need all the explicit factory class stuff that infests the more OO-pattern-y end of Java coding?
What @Arantor said; basically, by the time you're evaluating the constructor the instance has already been created (so that
$this
has something to refer to) and what you're doing is getting it into a usable state. (Indeed, if merely creating the object is enough and there's no further initialisation needed, a class need not have an explicit constructor method.)I don't use the factory class stuff, but I might use a static factory method on the (super)class if I know I might prefer an instance of a particular subclass depending on arguments.
-
@Watson I ask because an alternative approach is to have the
new
be a method of the class rather than a special operator (with the default implementation in the class of classes knowing how to do the basic object minting). At that point, you stop having explicit factories; those are just the classes themselves, as long as they honour the basic contract (you get a working instance back).
-
@dkf said in CodeSOD collection:
@Watson I ask because an alternative approach is to have the
new
be a method of the class rather than a special operator (with the default implementation in the class of classes knowing how to do the basic object minting). At that point, you stop having explicit factories; those are just the classes themselves, as long as they honour the basic contract (you get a working instance back).Not in PHP land, though the method you describe is how one would typically create a singleton - private constructor (so nothing can actually invoke the class via new), and you get the class via a static method that either constructs the object (which it can do because it knows about private methods) or returns the instance it already had.
That said in PHP land, factories tend to pop up either a) in the heart of your DI resolver and/or b) whenever you’re doing something with an Adapter pattern (whether that’s powered by your DI core or not)
-
@dkf said in CodeSOD collection:
@Watson I ask because an alternative approach is to have the
new
be a method of the class rather than a special operator (with the default implementation in the class of classes knowing how to do the basic object minting). At that point, you stop having explicit factories; those are just the classes themselves, as long as they honour the basic contract (you get a working instance back).Not really.
new
is the allocator and constructor is the initializer. You need to separate the two steps to be able to compose them for inheritance¹. E.g. in Python, both are simply methods:__new__
is a class method allocating the object and__init__
initializes it. You can actually do everything in__new__
, and you do that in some cases like specializing tuplestructs, but it works because Python has class methods that are called on the class metaobject where it can delegate to the base class metaobject. Languages that don't have metaobjects need a special concept for the allocator (new
).
¹ That's how Rust does without them—it does not have data inheritance, so it does not need to compose the initializers … and it still does have a bit of special logic for
Default
.
-
@Bulb said in CodeSOD collection:
Languages that don't have metaobjects need a special concept for the allocator (
new
).But that's enough about the mis-decisions in C++ for one thread.
-
@dkf Metaobjects I don't think C++ is the only language that either does not have meta-objects, or does not use them for instance allocation.