News for hackers. Stuff that matters.
Re:Learn just a little Awk (2010) by omginternets on Friday June 15, 2018 @06:35PM (#17324255)
>but I have never been so utterly _disoriented_ by bad code

One of these days, when the mood strikes, I'll upload the matlab script I inherited from my Ph.D supervisor.

Scientific programming is, by and large, an abysmal state of affairs.

Re:Learn just a little Awk (2010) by Waterluvian on Friday June 15, 2018 @11:00PM (#17325570)
At one job I had we got "help" from a local college professor on how to design our database. A lot of what he said made sense. And we were super green and databases were not our expertise or focus. Short on time, high on cash, we asked if he'd implement it for us.

I will never forget my gut wrenching feeling when I opened up one of the main provisioning scripts (in Python) to read the first two lines:

  True = 0
  False = -1
The rest of it was an unmaintainable disaster that may have worked. I learned so much that summer, having been forced to learn it all myself.
Re:Learn just a little Awk (2010) by nazri1 on Saturday June 16, 2018 @05:11AM (#17326683)
Re:Learn just a little Awk (2010) by felipemnoa on Saturday June 16, 2018 @02:04AM (#17326133)
>>I will never forget my gut wrenching feeling when I opened up one of the main provisioning scripts (in Python) to read the first two lines:

  True = 0
  False = -1
<<

Could you please explain what is so egregious about those two lines for those people that may not see it? Asking for a friend.

Re:Learn just a little Awk (2010) by Buge on Saturday June 16, 2018 @02:18AM (#17326177)
In most programming languages, including python, true is represented by 1 and false is represented by 0.

This script is changing it to be backwards, and python is flexible enough to allow that. But I would expect this would break most python libraries, because it's such a core language feature that's being completely restructured.

https://en.wikipedia.org/wiki/Boolean_data_type

Re:Learn just a little Awk (2010) by bcrack on Saturday June 16, 2018 @05:35AM (#17326735)
Actually Python 2 allows that, in Python 3 True, False, and None are reserved words [1].

[1] https://docs.python.org/3/whatsnew/3.0.html#changed-syntax

Re:Learn just a little Awk (2010) by cesarb on Saturday June 16, 2018 @08:09AM (#17327100)
Luckily, assigning to True and False affects only the current module. If he had changed __builtins__.True and __builtins__.False, on the other hand...

(Python has a search path: it looks first on the current module, then on the built-in __builtins__ module, which is where the built-in constants and functions reside.)

Re:Learn just a little Awk (2010) by poxrud on Saturday June 16, 2018 @03:17AM (#17326353)
When doing comparison checking, in most programming languages false is 0 and true is any other value.
Re:Learn just a little Awk (2010) by sorokod on Saturday June 16, 2018 @03:40AM (#17326432)
python is flexible enough to allow that

Is there a valid use case for changing the numeric values of True and False?

Re:Learn just a little Awk (2010) by sametmax on Saturday June 16, 2018 @07:26AM (#17326987)
No, it's legacy behavior and the community took the opportunity to fix it in Python 3, where it raises a SyntaxError.

Python 2 has _many_ quirks like this one. Python 3 was not just "it's unicode".

Re:Learn just a little Awk (2010) by Lio on Saturday June 16, 2018 @05:43AM (#17326755)
It’s, IMHO, a terrible idea but the one use I could imagine is if you are doing a lot of stuff with Unix exit codes, where exit code 0 is success. That would cover setting True = 0 ...maybe but not failure which is usually a positive exit code.

No! Actually I take it back this _is_ definitely still a terrible idea and will lead to certain madness for all involved. :)

Re:Learn just a little Awk (2010) by rgacote on Saturday June 16, 2018 @09:54AM (#17327394)
True != Success
Re:Learn just a little Awk (2010) by sorokod on Saturday June 16, 2018 @11:19AM (#17327720)
True = (True != Success)
Re:Learn just a little Awk (2010) by tzahola on Saturday June 16, 2018 @04:50AM (#17326624)
No.
Re:Learn just a little Awk (2010) by wingerlang on Saturday June 16, 2018 @02:16AM (#17326172)
True is normally 1, while False is 0. This seems like specific variable declarations as well, which you generally don't need as they are built into all languages e.g. "variable = false;"

However maybe the professor needed 'true/false' to represent something to be used in his formulas so this made sense to him. But who knows.

Re:Learn just a little Awk (2010) by kpcyrd on Saturday June 16, 2018 @10:11AM (#17327481)

    >>> True = 0
    >>> False = -1
    >>> if False: print('oh no')
False is now truthy and True is falsey. Note this only works in python2.
Re:Learn just a little Awk (2010) by djtriptych on Saturday June 16, 2018 @12:28AM (#17325839)
I literally almost choked on my drink reading this.
Re:Learn just a little Awk (2010) by fyi1183 on Saturday June 16, 2018 @02:47AM (#17326253)
That's a nice story, but True and False are keywords in python. Such assignment attempts are a syntax error.
Re:Learn just a little Awk (2010) by haldean on Saturday June 16, 2018 @03:02AM (#17326291)
This was not true in Python 2, and redefining True to False used to be a jokey way to break the interpreter in a bunch of fun ways.
Re:Learn just a little Awk (2010) by jwilk on Saturday June 16, 2018 @06:03AM (#17326801)
In fact, there's still lots of code in the wild that assigns to True/False, presumably for compatibility with very old Python versions:

https://codesearch.debian.net/search?q=%28%3Fm%29%5E%5Cs%2AT...