- 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
Once again demonstrating that a bad enough programmer can write PHP in any language.
Admin
Gotta admire the four levels of dictionary here (key, db, mongoDbTag and 'image'). And the reuse of the names
old_yaml_dataandnew_yaml_datafornew_yaml_dataandtemprespectively.Admin
New YAML gets overwritten with old YAML, except
imagefields and some MongoDB metadata. Sounds like some home-brewed kind of container upgrade system.Admin
... except the parameters and/or state to actually make it run keep getting 'juggled forward'
Admin
The best part is that key_exists allows you to check if the type is not a dictionary too (it returns
Nonein the non-dictionary case because ... they forgot to add a default return).But the code doesn't use it.
Admin
The main difference is that the custom
key_existwill not match a string, where ass in strwill do exactly what one expects.Sure it returns None if not a dict. The lack of an
elseis an... odd choice but it should work given how it's used.Now, whether the data may have different types is questionable given the script and the usage. One would hope not.
If it does, that's what we call a "very unfortunate design".
Admin
Throwing and catching exceptions is considered the optimum 'Pythonic' way to do control flow by the Python community. Also, key_exists doesn't define a return value when the arg is not a dict, which is more logical than the built-in operator which throws an exception on non collection types but which works on Lists.