- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I don't forsee the value of (for example)
I don't forsee the value of (for example)
I suppose we can say, '100% of functions documented'.
I suppose we can say, '100% of functions documented'.
However, it seems repetitive.
However, it seems repetitive.
Admin
The duff device is actually not really "C" and not really ugly. It also works in Javascript for example (with very nice results in some browsers) and is merely the (ab)use of switch/case fallthrough for easy optimisation purposes (when you have crappy compilers that can't optimize shit).
SuperZap for the win :D
Uh, part of the WTF is that he actually used os.path to build his devilish device. You see, as in using a tool to build a bigger tool doing exactly the same thing but in a more complicated, less readable and less optimized way
Admin
These are actually Python built-in private methods.
You are not supposed to call them directly (ever), as they usually have operators or built-in functions associated to them
Admin
C++ already has one.
Admin
C++ already has one.
// So that's the difference between reply and quote [^o)]
Admin
If Python is such a great language and you're not supposed to call them, ever, then why in the hell are you allowed to call them, ever?
Admin
Aside from the principle of least surprise being violated (I mean path("a").b.c + "d" = "a/b/c/d", etc.) this implementation actively prevents you from doing things you probably want and need to do with path names (such as append file extensions to them: path("My Documents/Thesis") + ".doc" does not have the effect you might (a) want and (b) expect). Nor will this do what one of the commands I often implement in any language does: catpath("this/", "/that") -> "this/that" ... yes indeed path("this/") + "/that" -> "this//that". So in essence the path object is less useful than a standard string.
The interesting question is ... where might this actually save you some typing?
Admin
Um.... Technically, that's not an operator in C++. (It doesn't perform any operation). The ISO C Standard refers to it as a "<FONT face="Times New Roman">punctuator". Some <FONT face="Times New Roman">punctuators are operators (* << ^) but others aren't (: ; {})</FONT></FONT>
<FONT face="Times New Roman"><FONT face="Times New Roman">Now, the funny thing is, in the early days of Borland C (back when it was called "Turbo C"), it was an operator of sorts. You could wrote completely illegal code like:</FONT></FONT>
void MyPrintf(char* format, ...)
{
printf(format, ...);
}
And it would compile & run with the expected results.
<FONT face="Times New Roman"><FONT face="Times New Roman">
</FONT></FONT>Admin
omygodyourerighticompletelygetyoursarcasmtheseunderscoresservenopurposeatallwhatacaseofeducationalexaggerationplzteachmeareallanguagelikethatglorifiedassembler
Admin
Special cases aren't special enough to break the rules.
Although practicality beats purity.
How can one define what one cannot call, ever?
Admin
What I meant was, the original post pointed out that the original developer should have used os.path.join() instead of creating such a convoluted construct. And I was pointing out that, yes, the original developer knew about it because he used it in his code that was posted above. So if he did, then isn't it even more of a WTF that he still coded what he did?
Admin
Read that closely. He said you are not supposed to call them DIRECTLY, not that are are not supposed to call them.
Much like in C++ you never do:
instead you write
python allows you to override getting member variables, so you can dofoo = bar.baz()
and have foo become /bar/baz. However, just because you can doesn't mean you should.
Admin
The name mangling is just a convention
init always fires when a class is instantiated, add overrides the "+", can you guess what mult does?
dict is a reference to the namespace dictionary.... basically, two underscores either side denote a 'special' method or attribute.
A single underscore prepended - ie. def _foo() is the usual indication of a private method/attribute.
Python has a philosophy of "we're all consenting adults". If someone releases a module, the normal functions are not likely to change dramatically overnight, so you can trust that your brand new programme which relies on module X is not going to break on the next release of X.
However, convention is - we make not guarantees for _ denoted methods. They're internal, call 'em if you want, we'd rather you didn't, they may not be there next release.
If you're calling a lot of 'private' methods/attributes, you doing it unpythonically.
Admin
I can see another reason for doing this; libraries in python is usually imported like:
import my.own.library
which corresponds to the file
"my/own/library.py"
Thus, at least the __getattr__ can make some sense for readability - but I guess I agree that this class is overengineered, particularly if it's just used for replacing a function call 4 places in the code :-)
If I was to guess, this code is written by some freshman that has just learned about python-__magics__ and thinks operator overloading is a cool thing. I could have done similar things some years ago.
Admin
cool
Addendum 2024-07-01 21:02: As a student of marketing, keeping up with the latest trends and theories while completing numerous case studies was overwhelming. I found myself needing extra help to manage my workload, so I turned to https://royalwriter.co.uk/ . Their writers provided insightful and well-researched essays that captured the essence of modern marketing strategies. This service allowed me to focus on practical projects and internships while maintaining my academic performance.