• Jos (unregistered)

    I think it's not OR's but OROR's, which sounds just like HORROR...

  • random_coder() (unregistered) in reply to Rhamphoryncus
    Rhamphoryncus:
    You're boned either way. The number of C files I've seen that randomly mixed tabs and spaces.. but hey, I have my editor set to show tabs, unlike all those presumably pro-tab programmers who are blissfully unaware of how they're butchering them.

    Python 3000 will make mixing tabs and spaces an error, finally fixing the problem of editors not distinguishing them properly.

    Fwiw, I agree that Fortran is insane. Python isn't anything like Fortran though, and gets a lot of unfair hatred because of the association.

    I actually won my boss over on KDevelop because it does exactly that - shows spaces vs tabs. We're mostly a Python shop, so I will say that you can definitely write obfusicated code in Python.

    I might submit a few maintenance scripts I've refactored - some previous employees had... um... some uneven skills.

  • Weave Jester (unregistered) in reply to fusbar
    fusbar:
    This is ofcourse a false statement from someone that hasn't read the code or understand python. The first, self.request().value(field,None) will look up if the is "key" field and if return its value, if not return None. But here, the key field could "hold" a value that is false which would render the hole statment false. This is not what would happen in your if field in self.request:, In your code, you only check if the key field is in the mapping object!
    I wasn't attempting to provide a literal translation, as the code is so bad merely rewriting it line for line would not result in a significant improvement. I thought this would be self-evident, as self.request is not a property, and may not have a __contains__ method, which would be required for the if statement condition to work. I also assume that self.request returns a dictionary-like object, and that value is analogous to get, which may not be true.

    If you insist, then the line could be rewritten as:

    if field in self.request and self.request[field]:

    But when you look at the rest of the code, any blank string that would trigger a false value would be ignored in any case, and any sensible implementation of self.request would only allow strings in its value. Not that you'd keep the rest of the code, anyway. If I had my way I'd pull out something like PyParsing and use that to parse the input instead of some insecure mess of splits, joins and replaces.

  • (cs)

    ...The most I ever did with it was to augment my PHP-based trouble ticket system so that it uses SpamAssassin to automatically reject spam messages.

    ...But even with my limited PHP knowledge, that code, which I do not understand at all, just "feels wrong".

    Further proof that you can write bad code in any language...

  • seebs (unregistered)

    Isn't it obvious?

    It's pipe-delimited.

  • Leif Arne Storset (unregistered)

    I just had to add that parsing Python's strict indentations is not significantly easier than using brackets, just (arguably) prettier. And the parser does not have one single style to understand; there is no rule whether to use tabs or spaces in Python (which can give all sorts of interesting defects).

  • steve (unregistered) in reply to slinkp

    request here would most likely be a callable weak reference. Any object can work like a function if you implement the call function (Python does overloading and such through special functions). A weak reference is created like so:

    self.request = weakref.ref( original_request_var )

    and then you use it each time like so:

    self.request().somemethod()

  • stevepm (unregistered) in reply to Weave Jester
    Weave Jester:
    if self.request().value(field, None):
    Which would be better expressed:
    if field in self.request:

    I hate to be 'that guy', but an empty string evaluates to False, so your example is not equivalent. '' == False, but it could be in self.request.

  • MrAlwaysRight (unregistered) in reply to mrprogguy
    mrprogguy:
    There are very few reasons scripting should be disabled these days.

    Security leaks in browsers. Most of them are triggered by Javascript.

  • Pegasus (unregistered) in reply to MrAlwaysRight

    The example code doesn't look pythonic at all (aside from the required syntax elements). I don't think the person writing this code would have fared any better in another language; perhaps he was one of those poor individuals who has brain damage from writing too much Basic code?

    If it were me, I would write a code generator/translator to take my python code and translate it to X language (the flavor of the day). It would allow me to maintain my development in what I know intimately, so my productivity wouldn't be significantly impacted (just the time it takes to write the translator).

    Captcha: wigwam Nuclear test series in the Pacific Ocean in the 1950s.

  • Speedbird (unregistered) in reply to Pythoneer

    The question is: Whi change python code into PHP that is the true WTF

  • Ptorq (unregistered) in reply to mrprogguy
    mrprogguy:
    Apparently you never programmed in Fortran. Everything had to start in column 7. Ridiculous.

    In the dialects of FORTRAN I've used, you don't have to start in column 7, you simply can't start BEFORE column 7, cos the first 5 characters of every line are reserved for (optional) line numbers and the 6th character is reserved for an (optional) line continuation mark. You're free to indent further if you like. (Provided you don't push the end of the line past column 72, since 73-80 are ... something, I forget what, I never used them. I think they were for card sequence numbers that were ignored by the compiler, so if you dropped your deck you could use the card sequence numbers to put it back in the proper order. I actually used a card deck precisely once, and it was input data, not source code.)

Leave a comment on “The Black Box of Or”

Log In or post as a guest

Replying to comment #:

« Return to Article