News for hackers. Stuff that matters.
Re:Myths of Enterprise Python by jrochkind1 on Tuesday March 24, 2015 @09:58AM (#9256550)
Meh.... I think he's right that there's no good reason _not_ to use Python.

But I think he overstates the case.

Calling Python "compiled" doesn't seem right -- he's more right that this doesn't matter, there's no reason not to use something because it's "not compiled".

Calling Python's typing "strong typing", eh, really? He provide a link to a wikipedia article on typing in general, how about a link to anyone else making the case that Python should be considered 'strongly typed', for a particular definition of 'strongly typed'? I'm dubious that it would be any definition of 'strongly typed' that those who think they want it... want. Again, I think a better argument might be: So what, you don't need strong typing for success, because of a b and c.

And the concurrency discussions is just silly. Sure, you can do _all sorts_ of things without multi-core concurrency, you may not need it or even benefit from it, and scaling to multi-process can sometimes work just fine too. But there are also _all sorts_ of cases where you do really want multi-core parallelism, and Python really doesn't have it -- and trying to justify this as "makes it much easier to use OS threads" is just silly. I guess it makes it 'easier' in that it protects you from some but not all race conditions in fairly unpredictable ways -- but only by eliminating half the conceptual use cases for threads in the first place (still good for IO-bound work, no longer good for CPU-bound work).

I think there's a reasonable argument to be made that Python will work just fine for 'enterprise' work. There are also, surely, like for all languages/platforms, cases where it would be unsuitable. By overstating the case with some half-truths and confusions, he just sounds like a fanboy and does not help increase understanding or accurate decision-making -- or confidence in the Python community's understanding!

Re:Myths of Enterprise Python by hyperpape on Tuesday March 24, 2015 @10:19AM (#9256695)
I can think of three ways of thinking about the term "strongly typed" once you realize it doesn't mean "statically typed".

1) It's meaningless--it's almost impossible to produce a real ranking of languages on the strength of their types.

2) These dynamic languages are all unityped because they're not statically typed. The fact that runtime tags won't allow certain operations to succeed has nothing to do with types.

3) Strongly typed is a rough and ready way of saying you don't do many implicit conversions.

I sympathize with (1). (2) is accurate, but really a terminological point. There's clearly a phenomenon to talk about, even if "typed" is the wrong word. I also sympathize with (3).

Python does far fewer implicit conversions than PHP, JavaScript or Perl. It even doesn't do at least one that Java does. So people often say Python is strongly, but dynamically typed. It's a real aspect of the language that you can view as a plus or minus.

Re:Myths of Enterprise Python by dgemm on Tuesday March 24, 2015 @10:15AM (#9256672)

  >>> 1 + "0"
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: unsupported operand type(s) for +: 'int' and 'str'
This is what strong typing refers to.
Re:Myths of Enterprise Python by reinhardt on Tuesday March 24, 2015 @10:57AM (#9256962)
It's not so clearcut. If this is evidence Python is strongly typed, would the following be evidence to the contrary?

  In [1]: 1 + 2.5
  Out[1]: 3.5

  In [2]: "foo" * 3
  Out[2]: 'foofoofoo'

  In [3]: [1, 2] * 3
  Out[3]: [1, 2, 1, 2, 1, 2]
Re:Myths of Enterprise Python by agentultra on Tuesday March 24, 2015 @11:09AM (#9257037)
It's not contrary, it's just convenience. One of the weaknesses in Python (if you can call it that) is that everything is an "object." The classes implementing string, list, and integer simply have methods that respond to those operators and rhs types.

  In [1]: "foo" + 3
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  <ipython-input-1-21582e79f06e> in <module>()
  ----> 1 "foo" + 3

  TypeError: cannot concatenate 'str' and 'int' objects
That's because the "special" method "__add__" implemented by the string class will raise TypeError if it gets any object that isn't an instance of a subclass of string.

In a way it is kind of funny to call it, "strongly typed," but it does work. Maybe it should be called, "instancely-typed."

Re:Myths of Enterprise Python by jrochkind1 on Tuesday March 24, 2015 @12:07PM (#9257465)
Okay, with this definition of 'strongly typed', can anyone come up with an example language that _isn't_ strongly typed?

It seems to make 'strongly typed' pretty meaningless, and this definition is probably _not_ what anyone who says they want a "strongly typed" langauge is using, so it hardly counters them to say that python is "strongly typed" under another definition, it's just confusing them with semantics.

(Of course, the people who say they want 'strongly typed' may have no idea what they're actually talking about, but wouldn't it be better to educate them then to take advantage of their ignorance to push your pro-python agenda?)

Re:Myths of Enterprise Python by Retra on Tuesday March 24, 2015 @12:33PM (#9257654)
C is not strongly typed.

In general, when someone is talking about strong typing, they are talking about silent failure for unintuitive or ambiguous constructs. For example, if the expression

    x = '1' + 1
results in an error, you are probably using a strongly-typed language. In C, this is equivalent to

    x = 32;
In javascript you get

    x = '11'
In PHP you get

    x = 2
These are examples of weak typing.
Re:Myths of Enterprise Python by agentultra on Tuesday March 24, 2015 @01:31PM (#9258050)
Strong, as opposed to weak, implying that there is type-constraint checking; it's just done at run-time in Python.

You could also describe Python's type system to be dynamic in that instances of the type meta-class define the constraints and objects (instances of a class) can have constraints added and removed at run-time. Python is still fairly strong in this regard in that the built-in classes are immutable (ie: it is a TypeError to assign a bound method to an attribute on a built-in class such as str).

I suggest "instancely-typed" because categories, unions, and type theory. I'm only coming to grips with that in that OCaml's type solver can be both awesome, annoying, and cryptic. And at the end of the day I'm still not sure what it's buying me other than proving exhaustive pattern matches in certain conditions, fast pattern dispatching, and requiring specialized operators (+, -, , / for ints... +.,-.,.,/. for floats... etc). I'm sure the enlightenment will come when it stops becoming such a PITA to write a basic program.

Sometimes not having to satisfy the constraints up-front makes exploratory programming (where the constraints are not specified and known up front) easier. Python is going the annotation route in newer versions of the language which is rather useful so that tools could be written to verify consistency up-front (or at least provide hints).

Re:Myths of Enterprise Python by GeneralMayhem on Tuesday March 24, 2015 @12:34PM (#9257663)
Javascript comes to mind, since it only functionally has I think 5 types (string, number, boolean, array, object - and the line between array and object is blurry) and no user-added ones. There are no built-in type semantics whatsoever other than what properties are present on an object at the time of its use. Functions of different arities aren't even type-differentiable (although arity is available as a reflectable value).
Re:Myths of Enterprise Python by task_queue on Tuesday March 24, 2015 @12:37PM (#9257684)
I don't know. Runtime type checking is necessary because the language doesn't have constructs which allow dispatching based on type.

Otherwise, you'd run into Python's strong type system when doing an incompatible operation.

Re:Myths of Enterprise Python by task_queue on Tuesday March 24, 2015 @11:50AM (#9257354)
No. That would be evidence of polymorphism. Those objects have explicit ways of handling those operations based on the types or interface of the object left/right of the operand.

The interpreter/type system is doing nothing implicitly behind the scenes to coerce the objects.

Re:Myths of Enterprise Python by dheera on Tuesday March 24, 2015 @11:39AM (#9257260)
I love Python for things like this. 'foo' * 3 is so intuitive. Seriously, to hell with Java's StringWriters and StringBuffers and StringBufferInputStream throws IOException.
Re:Myths of Enterprise Python by natural219 on Tuesday March 24, 2015 @11:11AM (#9257060)
This is a great example, which is why I think "strong vs. weak" typing is properly thought of as a scale rather than a classification. Which is used properly in the blog post, merely comparing some instances of implicit conversion in JVM that make less sense by default (all of your examples can be argued to be deliberately useful, as opposed to Javascript WAT-style statements).
Re:Myths of Enterprise Python by yen223 on Tuesday March 24, 2015 @11:47AM (#9257332)
I agree with your second point. Python doesn't pretend to be strongly-typed, but it does use its, uh, 'loose' typing to great advantage.

I particularly like Python's arbitrary-precision integers, where ints are implicitly converted to longs, allowing you to have the performance of ints without the problem of integer overflows.

Re:Myths of Enterprise Python by jrochkind1 on Tuesday March 24, 2015 @12:14PM (#9257510)
You say "python doesn't pretend to be strongly-typed", yet the OP is claiming it _is_ strongly typed.

I think the reality is "strongly typed" doesn't really mean much.

Re:Myths of Enterprise Python by marcosdumay on Tuesday March 24, 2015 @12:07PM (#9257469)
No. Why would it?

As most OO languages, Python has function overloading based on the type of the parameters. The fact that those operators do different things when operating on different types is evidence that Python has strict types, not loose.

Re:Myths of Enterprise Python by task_queue on Tuesday March 24, 2015 @01:58PM (#9258269)
Not overloading in the sense of Java and what not.

There is no dynamic dispatch based on types in the interpreter, you have to manually do it in the body of the method, of which you have one.

Re:Myths of Enterprise Python by username223 on Tuesday March 24, 2015 @11:09AM (#9257049)
Which makes it ambiguous:

    Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) 
    [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1/2.3
    0.4347826086956522
    >>> 1 / 2.3
    fish: Job 2, 'python' terminated by signal SIGSEGV (Address boundary error)
(I didn't expect that last part.)
Re:Myths of Enterprise Python by crdoconnor on Tuesday March 24, 2015 @11:18AM (#9257122)
There's something weird going on with your system. There is absolutely no way under normal circumstances that you'd get a segmentation fault dividing 1 by 2.3.
Re:Myths of Enterprise Python by a_bonobo on Tuesday March 24, 2015 @11:36AM (#9257241)

    Python 2.7.5 (default, Nov  3 2014, 14:26:24) 
    [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1/2.3
    0.4347826086956522
    >>> 1 / 2.3
    0.4347826086956522
Identical output under Python 3.3.2
Re:Myths of Enterprise Python by username223 on Tuesday March 24, 2015 @01:00PM (#9257824)
> There's something weird going on with your system.

Yep -- it seems like a readline problem. As you can tell, I don't use this machine for Python.

Re:Myths of Enterprise Python by serve_yay on Tuesday March 24, 2015 @12:35PM (#9257671)
Indeed, it is strongly typed but not statically typed. The only thing is, almost every language is strongly typed now, the only counterexample I know is C (and derivatives). Not that there aren't others, but I'm not sure there are others that anyone really uses. So I wonder if it is really even worth saying a language is "strongly typed" anymore, it's hardly ever a distinction. Might as well just say "not C".
Re:Myths of Enterprise Python by falcolas on Tuesday March 24, 2015 @12:51PM (#9257763)
C, JavaScript, PHP, lisp...

There are many popular and weakly typed languages in use today.

Re:Myths of Enterprise Python by serve_yay on Tuesday March 24, 2015 @12:54PM (#9257781)
JS is strongly typed, not sure about PHP but I don't think so. lisp is not a language, it's a family of languages
Re:Myths of Enterprise Python by pythonautical on Wednesday March 25, 2015 @02:09PM (#9264778)
> [] + {}

"[object Object]"

> {} + []

0

JS and PHP are the prototypical examples of weak typing.

Re:Myths of Enterprise Python by serve_yay on Saturday March 28, 2015 @12:11AM (#9280480)
Again, not sure about PHP. But no, JS is strongly typed. What you've shown there is coercion, not type-punning or anything of the sort.
Re:Myths of Enterprise Python by wbkang on Tuesday March 24, 2015 @10:13AM (#9256652)
Strongly typed is pretty precisely defined and Python is certainly strongly typed.
Re:Myths of Enterprise Python by mdonohue on Tuesday March 24, 2015 @10:16AM (#9256684)
Defined as what? The Wikipedia article says the definition is unclear:

Languages are often colloquially referred to as "strongly typed" or "weakly typed". In fact, there is no universally accepted definition of what these terms mean. In general, there are more precise terms to represent the differences between type systems that lead people to call them "strong" or "weak".

Re:Myths of Enterprise Python by acbart on Tuesday March 24, 2015 @10:15AM (#9256669)
I agree that there are precise definitions of the phrase "strongly typed", but from my experience if you put 10 computer scientists in the same room, you'll hear 3 different definitions of what it means.
Re:Myths of Enterprise Python by jammycakes on Tuesday March 24, 2015 @10:21AM (#9256714)
True, but the complaint that people tend to come up with is that Python is not statically typed. What they are looking for here are things such as clear, accurate and reliable IntelliSense, and the ability to right click on a method definition, select "Rename", and be assured that the refactoring will be propagated through to every usage throughout your codebase with no false positives and no false negatives.
Re:Myths of Enterprise Python by crdoconnor on Tuesday March 24, 2015 @10:36AM (#9256826)
Strong typing saves you from a whole universe of obscure bugs at no extra cost.

Static typing would be nice, but not in a Java or C# or C++ way. The extra verbosity makes it not worth the benefits. Sure, you get slightly more reliable intellisense, but at the expense of a program that's 15-20% longer.

Re:Myths of Enterprise Python by eliben on Tuesday March 24, 2015 @11:35AM (#9257230)
But Python is strongly typed. A language can be dynamically typed, and strongly typed - no problem with that. More details in http://eli.thegreenplace.net/2006/11/25/a-taxonomy-of-typing...
Re:Myths of Enterprise Python by agentultra on Tuesday March 24, 2015 @10:58AM (#9256967)
There are plenty of options for concurrent and parallel operations in Python[0]. It is heavily used in data analytics and the scientific programming communities. Though it does often need a little help from C to take advantage of SMP hardware.

[0] https://wiki.python.org/moin/ParallelProcessing

Re:Myths of Enterprise Python by slantedview on Tuesday March 24, 2015 @01:34PM (#9258068)
Python is compiled in the sense that it produces bytecode, but in being so it lacks the benefits of other compiled languages such as thorough compile time error checking. I've found that this is sometimes why people don't even notice the compiler.
Re:Myths of Enterprise Python by slantedview on Tuesday March 24, 2015 @01:43PM (#9258139)
[OS threads are] "no longer good for CPU-bound work" "Python will work just fine for 'enterprise' work"

These two statements conflict.