If you can read this, either the style sheet didn't load or you have an older browser that doesn't support style sheets. Try clearing your browser cache and refreshing the page.

(IT World)   No, Python was not named after the snake. Know what I mean? Wink wink. Nudge nudge. say no more   (itworld.com) divider line 50
    More: Interesting  
•       •       •

2808 clicks; posted to Geek » on 20 Mar 2014 at 11:56 AM (39 weeks ago)   |  Favorite    |   share:  Share on Twitter share via Email Share on Facebook   more»



50 Comments   (+0 »)
   
View Voting Results: Smartest and Funniest
 
2014-03-20 12:04:08 PM  
27.media.tumblr.com
 
2014-03-20 12:10:30 PM  
 
2014-03-20 12:32:37 PM  
imgs.xkcd.com
 
2014-03-20 12:43:24 PM  
It's always amusing how many things in IT got their names because of limitations in the length of file names, word bit lengths, or obscure technical details of the system originally implemented on (see: LISP).
 
2014-03-20 12:52:30 PM  
Holy crap. Anyone who doesn't know this should not be browsing on the "Geek" tab.
 
2014-03-20 01:20:55 PM  

baconbeard: Holy crap. Anyone who doesn't know this should not be browsing on the "Geek" tab.


Yes, if there's one fark tab that justifies elitism, it's definetly the one named for circus freaks.
 
2014-03-20 01:30:33 PM  
I used to program in FORTH.  Talk about write-only.
 
2014-03-20 01:51:08 PM  

manbart: [imgs.xkcd.com image 518x588]



So I actually did that:

In [8]: import antigravity
In [9]: Created new window in existing browser session.
[Browser window opens up]

In [9]: antigravity
Out[9]: <module 'antigravity' from '/usr/lib/python2.7/antigravity.pyc'>

In [10]: antigravity??
Type:       module
String Form:<module 'antigravity' from '/usr/lib/python2.7/antigravity.pyc'>
File:       /usr/lib/python2.7/antigravity.py
Source:
import webbrowser
webbrowser.open("http://xkcd.com/353/")


 Awesome.
 
2014-03-20 01:58:10 PM  
I wonder what Black Mamba thinks about all this.
3.bp.blogspot.com
 
2014-03-20 02:35:12 PM  

meyerkev: manbart: [imgs.xkcd.com image 518x588]


So I actually did that:

In [8]: import antigravity
In [9]: Created new window in existing browser session.
[Browser window opens up]

In [9]: antigravity
Out[9]: <module 'antigravity' from '/usr/lib/python2.7/antigravity.pyc'>

In [10]: antigravity??
Type:       module
String Form:<module 'antigravity' from '/usr/lib/python2.7/antigravity.pyc'>
File:       /usr/lib/python2.7/antigravity.py
Source:
import webbrowser
webbrowser.open("http://xkcd.com/353/")

 Awesome.


;)

/Bonus points for using IPython
//Are you on 3.4.0 yet?
 
2014-03-20 02:39:49 PM  

manbart: //Are you on 3.4.0 yet?


2.7.6.

Some of our dependencies require 2.x.x
 
2014-03-20 02:51:10 PM  
img.fark.net
 
2014-03-20 03:37:09 PM  
I use Python every day.  My clients rely on it for "important stuff".  It's as mainstream as any language at this point, just more readable than most.
 
2014-03-20 03:39:41 PM  

Iszael: I use Python every day.  My clients rely on it for "important stuff".  It's as mainstream as any language at this point, just more readable than most.


Everybody remember Apple's recent Goto Fail bug? Literally impossible in Python, because indentation and nesting can't contradict each other.
 
2014-03-20 03:51:11 PM  
So.. what crackhead idea was it to name a programming environment .NET?
 
2014-03-20 04:24:12 PM  
I know everyone seems to love Python, but I just don't get it.  Maybe it's just having spent too much time on Windows?  I don't know.  I use a fair bit, but I'm certainly not an expert.  Still, I'm never like, 'Oh sweet, I'll use Python'.  It's always like, 'ehhhh, well, ugh...the source code for this is in Python.....well, I guess I'll use it'.
 
2014-03-20 04:37:25 PM  

Iszael: It's as mainstream as any language at this point, just more less readable than most.


FTFY. Dynamic typing is unreadable.
 
2014-03-20 04:45:32 PM  
I'm in love with golang right now. Python always rubbed me the wrong way.
 
2014-03-20 04:47:24 PM  

impaler: Iszael: It's as mainstream as any language at this point, just more less readable than most.

FTFY. Dynamic typing is unreadable.


Yeah, but it's statically weakly typed, NOT dynamically typed. 

And static weak typing is best typing.  Because 22 != "22", but x ="22"; x=22 is valid code.
 
2014-03-20 08:40:59 PM  
No - no more! I spent 10 hours today wrestling with python and pandas. I am officially pythoned out for the day.
 
2014-03-20 08:56:21 PM  

czetie: Iszael: I use Python every day.  My clients rely on it for "important stuff".  It's as mainstream as any language at this point, just more readable than most.

Everybody remember Apple's recent Goto Fail bug? Literally impossible in Python, because indentation and nesting can't contradict each other.


No, but I'm sure Edsger Dijkstra was not amused.
 
2014-03-20 09:22:56 PM  

impaler: Iszael: It's as mainstream as any language at this point, just more less readable than most.


FTFY. Dynamic typing is unreadable.


The difference between 4 spaces and a tab is unreadable
 
2014-03-21 08:04:37 AM  

meyerkev: impaler: Iszael: It's as mainstream as any language at this point, just more less readable than most.

FTFY. Dynamic typing is unreadable.

Yeah, but it's statically weakly typed, NOT dynamically typed.

And static weak typing is best typing.  Because 22 != "22", but x ="22"; x=22 is valid code.


Python is dynamically strongly typed. And it's perfectly readable.
 
2014-03-21 09:42:31 AM  

batlock666: Python is dynamically strongly typed. And it's perfectly readable.


Also known as "duck typing". Another way to look at is that objects have types, but the names that refer to them do not. Hence to extend the example, I can write y = x*3 and it will behave according to the type of the value of x. One consequence of this is that Python makes it really easy to write code that operates on many different types without any of the syntactic sugar required by strongly-typed languages.

Once you start writing Python and notice how rarely you actually have to check the type of a value, you begin to realize the beauty of dynamic typing, and that a lot of other languages have tons of syntactic baggage just to overcome the limitations that static typing introduced in the first place.

Personally I find Java to be far less readable, not least because of the repetition and verbosity and repetition of the syntactic sugar. And don't even get me started on C, which practically invites you to make stupid errors that are easily missed in review (and kudos to the authors of Java for repeating all the worst mistakes of C).

Memo to future language designers: it's survivable to allow assignment to be an expression; and it's OK to not have a formal Boolean type; but having both features in the same language is asking for trouble.
 
2014-03-21 11:04:44 AM  

ParanoidAgnostic: impaler: Iszael: It's as mainstream as any language at this point, just more less readable than most.


FTFY. Dynamic typing is unreadable.

The difference between 4 spaces and a tab is unreadable


Whitespace has nothing to do with types.
 
2014-03-21 11:05:53 AM  

czetie: Once you start writing Python and notice how rarely you actually have to check the type of a value, you begin to realize the beauty of dynamic typing,


Really? When you start really programming, and the compiler balks when you try to add meters to feet, you quickly realize the beauty of strong types.
 
2014-03-21 11:56:05 AM  

impaler: czetie: Once you start writing Python and notice how rarely you actually have to check the type of a value, you begin to realize the beauty of dynamic typing,

Really? When you start really programming, and the compiler balks when you try to add meters to feet, you quickly realize the beauty of strong types.


Python is strongly typed. When you start really programming, you might realize the difference between "strong types" and "static types", and why strong dynamic is such a powerful combination.
 
2014-03-21 01:27:30 PM  

impaler: ParanoidAgnostic: impaler: Iszael: It's as mainstream as any language at this point, just more less readable than most.


FTFY. Dynamic typing is unreadable.

The difference between 4 spaces and a tab is unreadable

Whitespace has nothing to do with types.


It has a lot to do with readability.
 
2014-03-21 04:29:36 PM  

impaler: czetie: Once you start writing Python and notice how rarely you actually have to check the type of a value, you begin to realize the beauty of dynamic typing,

Really? When you start really programming, and the compiler balks when you try to add meters to feet, you quickly realize the beauty of strong types.


I've used explicitly-typed languages (which is what I think you mean by "strongly-typed") and have yet to see any code that takes advantage of strong typing to match physical units.  In fact, most explicit typing systems wouldn't be up to the task, since every combination of units would require a new type to be defined.  I am curious what language/tool you are talking about that can catch unit errors at compile time.

OTOH, an implicitly- but dynamically-typed language like Python could be up to the task, since it can create types on the fly.  But then you'd have to do calculations (with unit-checking) in Python, which isn't usually a good idea.

Personally, I've never found explicit typing to save me more time debugging than the extra effort it requires, and so, however beautiful it is, as a practical matters is hasn't helped me much.  YMMV
 
2014-03-21 06:03:04 PM  

aerojockey: I've used explicitly-typed languages (which is what I think you mean by "strongly-typed") and have yet to see any code that takes advantage of strong typing to match physical units.  In fact, most explicit typing systems wouldn't be up to the task, since every combination of units would require a new type to be defined.  I am curious what language/tool you are talking about that can catch unit errors at compile time.


SI units was just an example. It works equally well if you have a type for screen coordinates vs window coordinates vs Lat/Lon coordinates of a map in your window etc.

To answer your question though, the language is C++. Described at the 20 minute mark: Link

I actually did it a different way than described, but I might change after seeing that.
 
2014-03-21 06:24:56 PM  

impaler: To answer your question though, the language is C++. Described at the 20 minute mark: Link


Can't watch it now.

I know you can technically do it in C++ and such.  My question was about tools that are actually deployed and using static types to check for physical units.  I'm not asking about screen coordinates and window coordinates.  Physical units are much harder, because they combine arbitrarily.

Say I have x which is in inches, and y which is in seconds.  I want the average speed so I write z=x/y.  What type is z?  You'd have to define a type and operations for every possible combination you need.  Unless they added some powerful stuff since I last checked, C++ and every other statically-typed language I know of is inadequate for this.

So, I'll just go ahead and opine that physical units are a bad example.  As for enforcing simple things like window versus screen coordinates, I'm unimpressed.  It might help catch a bug here and there, but too few to justify the extra effort, at least for me.  Again, YMMV.

(But I would suggest that if you're getting lots of bugs due to mixing up rows and columns, then maybe you're just using the compiler as a crutch to cover your poor programming habits.)
 
2014-03-21 06:29:09 PM  

aerojockey: Physical units are much harder, because they combine arbitrarily.


No, they don't.

I want the average speed so I write z=x/y. What type is z?

The SI unit: meters per second.
 
2014-03-21 06:33:14 PM  
Another good one is radians and degrees.
 
2014-03-21 06:54:55 PM  

impaler: aerojockey: Physical units are much harder, because they combine arbitrarily.

No, they don't.


Sorry, you're flat-out wrong.  Even if you constrain yourself to just SI units (and that's moving the goalposts, since your first example tried to add meters to feet), you have arbitrary combinations of just those units.

m^2/s  kg/m^3  kg*m^2/s^3  kg*m^2/s^2/K  etc. etc.

C++'s type system simply isn't powerful enough to handle this automatically, nor is any other tool's static type system that I know of.  I'm sure someone's tried it in a tool somewhere, but I don't know about it, which is why I was asking.


impaler: aerojockey: Physical units are much harder, because they combine arbitrarily.

No, they don't.

 I didn't ask what units it was.  I asked you what type it was.  I'll be more explicit.  You define types for inches and seconds:


class Inch {...}
class Second {...}

Inch x = Inch(4);
Second y = Second(6);

What type do you make the expression "x/y"?  Where is it defined?  If you want to allow arbitrary combinations of just one division, then you have to define about N^2 classes, where N is the number of base units.  And that's just one division.  Even if you only define SI units (7 units plus one unitless), you will still need 56 classes to represent all combinations of one division.  Now throw in arbitrary numbers of multiplications and divisions.  Yeah.

If you don't want to allow arbitrary combinations of units, then your system sucks and is inadequate for all but the simplest physical calculations.

So I'm sorry, I still say physical units are a bad example.  Static typing in C++ and the like just isn't powerful enough to help with physical units.
 
2014-03-21 07:03:19 PM  

aerojockey: So I'm sorry, I still say physical units are a bad example.  Static typing in C++ and the like just isn't powerful enough to help with physical units.


The straight-up BEST way we have to solve this problem* is Apps Hungarian Notation:  http://www.joelonsoftware.com/articles/Wrong.html

*Without writing 87 kajillion classes and spending WAY more time than it's worth.

/Now what it's great for is refactoring.  Need to rename a function?  Watch the compiler yell at you about every single place where that function gets used.
 
2014-03-21 07:15:32 PM  

meyerkev: The straight-up BEST way we have to solve this problem* is Apps Hungarian Notation: http://www.joelonsoftware.com/articles/Wrong.html


I agree, sort of.  There is no reason a compiler couldn't be written that could check physical units at compile time.  And if someone did that, and if the tool didn't suck, that would be the best way we have to solve this problem.  Also, have you ever tried to use Hungarian notation with crazy unit combinations?  Not fun.

The reason I am interested in this is because, unlike the case of keeping rows and columns straight, physical units are complicated enough that explicitly typing them and letting the compiler catch unit errors might actually be worth the trouble.  But no compilers I know of are up to the task.
 
2014-03-21 07:16:08 PM  

czetie: Also known as "duck typing". Another way to look at is that objects have types, but the names that refer to them do not. Hence to extend the example, I can write y = x*3 and it will behave according to the type of the value of x. One consequence of this is that Python makes it really easy to write code that operates on many different types without any of the syntactic sugar required by strongly-typed languages.

Once you start writing Python and notice how rarely you actually have to check the type of a value, you begin to realize the beauty of dynamic typing, and that a lot of other languages have tons of syntactic baggage just to overcome the limitations that static typing introduced in the first place.

Personally I find Java to be far less readable, not least because of the repetition and verbosity and repetition of the syntactic sugar. And don't even get me started on C, which practically invites you to make stupid errors that are easily missed in review (and kudos to the authors of Java for repeating all the worst mistakes of C).

Memo to future language designers: it's survivable to allow assignment to be an expression; and it's OK to not have a formal Boolean type; but having both features in the same language is asking for trouble.


I've picked up python professionally in the past six months, and I've played in the shallow end of the java pool with Processing. Python, as far as I'm concerned, has it all over java. I get really sick of trying to figure out where the fark I misplaced a closing "}" with multiple nested blocks of code in Java. And fark semi-colons up their semi-colon. Who the hell thought this was a good idea?

One thing that Java does have that I really, really wish python had better provisions for is modifying lists and arrays in place. Sure, you can use enmumerate() or range(len(list)) if you're feeling pissy and just want it done, but both are brutish approach that are, in my experience, rather fragile. I feel like I'm being wasteful creating new lists when I need to modify an existing list, and with many of the data sets I'm working with I have to be careful about deleting lists to conserve as much memory as possible.

I did pick up the ability to iterate over multiple lists simultaneously using zip() today, and it allowed me to solve a horrendously hairy problem with several hundred raw data files containing several million observations that were time stamped. Made me feel like a champ: when I showed my DB guy - who writes code that looks like moon runes to my amateur eyes - that block of code he scratched his head and said "what the fark is this, I've been trying to solve this problem time stamp problem for months."

ParanoidAgnostic: It has a lot to do with readability.


I've never understood this complaint about Python. FFS people if your IDE doesn't support displaying white space just dump it into notepad++. Problem solved, literally in seconds.

As a bonus, the strong white space requirement endure that you have to produce code that is (relatively) intelligible compared to shortcuts in C variants and java.  And don't get me started on the cowboys that ignore any conventions or consistency in how they open and close blocks...
 
2014-03-21 07:26:54 PM  

aerojockey: nch x = Inch(4);
Second y = Second(6);

What type do you make the expression "x/y"?


class MetersPerSecond

inline MetersPerSecond operator / (Meters m, Seconds s){
return m.value/s.value;
}

class Inch
Meters operator(){
return this->value * INCHES_PER_METER;
}

All length goes to meters, all time goes to seconds, all volume goes to liters, etc.

And done.

I know it works, because I have code that uses it.
 
2014-03-21 07:29:11 PM  

aerojockey: The reason I am interested in this is because, unlike the case of keeping rows and columns straight


Keeping rows and columns straight?
 
2014-03-21 07:39:44 PM  

impaler: aerojockey: nch x = Inch(4);
Second y = Second(6);

What type do you make the expression "x/y"?

class MetersPerSecond

inline MetersPerSecond operator / (Meters m, Seconds s){
return m.value/s.value;
}

class Inch
Meters operator(){
return this->value * INCHES_PER_METER;
}

All length goes to meters, all time goes to seconds, all volume goes to liters, etc.

And done.

I know it works, because I have code that uses it.



Sigh.  You're clearly ignorant about the sheer number of different unit combinations real-world scientists and engineers encounter.  I am telling you, writing boilerplate classes by hand like this doesn't scale up to my needs.  I'd have to write thousands of classes and define thousands of operators just to support the operations I have now.  And every time I'd write a new calculation, I'd have to define more.
 
2014-03-21 08:07:22 PM  
Hey, impaler, want some more hilarity.

I have some matrices for which each row and column has a different unit.  Don't worry, they're all SI units.  I want to make sure when I multiply and add and invert the matrices and stuff, the compiler will create an error if the resulting vector isn't doesn't have the correct types.

Oh, and BTW, the matrices and vectors are dozens of rows and columns wide, because each point is a different output of a system, which can be any of different kinds of measures.  I have pressures here, temperatures there, flow rates over here, a few places where I measure electric charge, some lengths and angles corresponding valve control settngs, and so on.  And because this is an LQR system there's a buttload of intermediate matrices all which need their own combinations of units.

impaler, please tell me, how can C++'s static type system help me avoid unit errors in this problem.
 
2014-03-21 08:53:04 PM  

Elegy: I've never understood this complaint about Python. FFS people if your IDE doesn't support displaying white space just dump it into notepad++. Problem solved, literally in seconds.

As a bonus, the strong white space requirement endure that you have to produce code that is (relatively) intelligible compared to shortcuts in C variants and java.  And don't get me started on the cowboys that ignore any conventions or consistency in how they open and close blocks...


It's a pain in the arse when working collaboratively on a Python script. There's always someone who doesn't have their editor set up to enter 4 spaces when they insert tabs and manages to completely break the program by indenting the wrong way.

It's also ridiculous to change the display settings so that invisible characters are visible. Why not just use a language which uses visible characters to differentiate blocks in the first place?

Whitespace is for human readability and the way human beings understand things frequently differs from the way a computer would. Sometimes it is clearer to put 3 statements on one line, or add a little indenting so that things line up better. Making whitespace meaningful to the computer takes away that flexibility
 
2014-03-21 09:26:34 PM  

aerojockey: Hey, impaler, want some more hilarity.

I have some matrices for which each row and column has a different unit.  Don't worry, they're all SI units.  I want to make sure when I multiply and add and invert the matrices and stuff, the compiler will create an error if the resulting vector isn't doesn't have the correct types.

Oh, and BTW, the matrices and vectors are dozens of rows and columns wide, because each point is a different output of a system, which can be any of different kinds of measures.  I have pressures here, temperatures there, flow rates over here, a few places where I measure electric charge, some lengths and angles corresponding valve control settngs, and so on.  And because this is an LQR system there's a buttload of intermediate matrices all which need their own combinations of units.

impaler, please tell me, how can C++'s static type system help me avoid unit errors in this problem.


Use a double.
 
2014-03-21 09:27:42 PM  

impaler: Use a double.


Actually, Ill get back to this.
 
2014-03-21 09:32:41 PM  

aerojockey: Sigh.  You're clearly ignorant about the sheer number of different unit combinations real-world scientists and engineers encounter.  I am telling you, writing boilerplate classes by hand like this doesn't scale up to my needs.  I'd have to write thousands of classes and define thousands of operators just to support the operations I have now.  And every time I'd write a new calculation, I'd have to define more


I am a real world engineer.

Thousands of unit combinations?
Link

Most will use less than a dozen for any given program.
 
2014-03-21 09:36:59 PM  

aerojockey: I have some matrices for which each row and column has a different unit.  Don't worry, they're all SI units.  I want to make sure when I multiply and add and invert the matrices and stuff, the compiler will create an error if the resulting vector isn't doesn't have the correct types.


Each row AND column has a different unit (i.e. each cell as a different unit), and you're performing matrix math on this, and getting a sensible result?

If true,you've found a highly specialized case where it would be better to use a double.
 
2014-03-21 09:39:28 PM  

impaler: impaler: Use a double.

Actually, Ill get back to this.


Don't bother.  I made the taunttastic post because I thought you were being obtuse, but if you really think that a few boilerplate classes in C++ can solve all your problems with physical units, there's probably no talking to you.
 
2014-03-21 09:51:37 PM  

aerojockey: Don't bother.  I made the taunttastic post because I thought you were being obtuse, but if you really think that a few boilerplate classes in C++ can solve all your problems with physical units, there's probably no talking to you.


Did I say it will solve all the problems? No.

Do I think it will help with most of them? No

I KNOW it will help..

Because I use it. It's mostly radians and degrees that it kicks ass with. Also seperate types for program window coordinates and subwindow coordinate conversion.
 
2014-03-21 10:00:53 PM  

aerojockey: Sigh.  You're clearly ignorant about the sheer number of different unit combinations real-world scientists and engineers encounter.  I am telling you, writing boilerplate classes by hand like this doesn't scale up to my needs.  I'd have to write thousands of classes and define thousands of operators just to support the operations I have now.  And every time I'd write a new calculation, I'd have to define more.



Link

John J. Barton and Lee R. Nackman described a wonderful solution to the units problem in their 1994 book, Scientific and Engineering C++ (Addison-Wesley), but even though I received a copy of the book, I didn't notice their work when it came out. To be honest, I found the book rather boring, and I read little of it. However, I read Barton's and Nackman's column in the January 1995 C++ Report in its entirety, and that column presented a stripped-down (and vastly more readable) version of their approach. Three things about it struck me. First, it covered all possible combinations of units, not just the combinations with names. That is, we have a name for distance divided by time (velocity) and for force divided by distance squared (pressure), but we don't have a name for distance times time squared divided by angular velocity cubed. At least not one that I know of. The B&N approach ensures dimensional unit correctness, even if calculations yield heretofore unneeded combinations of units.

The second thing that got my attention about the B&N solution was its runtime cost: there isn't any.
 
2014-03-21 11:11:32 PM  

aerojockey: Sorry, you're flat-out wrong.  Even if you constrain yourself to just SI units (and that's moving the goalposts, since your first example tried to add meters to feet), you have arbitrary combinations of just those units.

m^2/s  kg/m^3  kg*m^2/s^3  kg*m^2/s^2/K  etc. etc.


This post is really bugging me.

No, they aren't arbitrary. Meters divided by seconds just doesn't arbitrarily result in a new value, it results in velocity.

No, I didn't constrain my self to SI units, I just assumed someone that programs would realize that for every quantity, you just need ONE SI base unit. And then you only need 2 functions for each non-SI BASE unit (there are only 7 base units - length, mass, time, current, temperature, amount of substance, luminous intensity).

Want to find miles traveled in 2 hours at 4 inches per minute? Well the meters per second function will balk at inches and minutes (unless you overload the inches and minutes class to return the appropriate SI unit - in which case they will just return the RIGHT value), so one invokes the proper InchesToMeters(), and MinutesToSeconds() functions. The result: MetersPerSecond.

From that, the MetersPerSecond value multiplied by the hours value will balk, but then you just call the HoursToSeconds() function. Result: Meters.

No to get your miles result, you just call the MetersToMiles().

So for minutes, hours, inches, miles, (4 units) you only need 8 functions.(only 4 of which just called)
InchesToMeters,
MetersToInches,
MilesToMeters
MetersToMiles,
MinutesToSeconds,
SecondsToMeters,
HoursToSeconds,
SecondsToHours.
 
Displayed 50 of 50 comments

View Voting Results: Smartest and Funniest


This thread is closed to new comments.

Continue Farking
Submit a Link »
On Twitter





In Other Media


  1. Links are submitted by members of the Fark community.

  2. When community members submit a link, they also write a custom headline for the story.

  3. Other Farkers comment on the links. This is the number of comments. Click here to read them.

  4. Click here to submit a link.

Report