3 ms·
I think Python's niche is understood to be as a readable, concise, batteries-included language suitable for scripting, prototyping, and application development
by dkarl 13y ago
I think Python's niche is understood to be as a readable, concise, batteries-included language suitable for scripting, prototyping, and application development on a small-to-medium scale (and large scale for some people, but that's controversial,) and serving as a convenient interface to C and C++ libraries in all those roles. Python differentiates itself from similar languages in the niche by elevating simplicity, explicitness, and readability over conciseness and expressiveness. That's the conventional wisdom, anyway.
I'd say the biggest challenge to Python in that niche is the emergence of type inference for statically typed languages. Not too long ago, the difference between a statically typed language and Python was
List<Foo> foos = new List<Foo>();
foos.add(new Foo(2));
foos.add(new Foo(4));
versus
foos = [ Foo(2), Foo(4) ]
Now, a static language might look more like this:
val foos = List(Foo(2), Foo(4))
As far as I know, there still isn't a statically typed language that matches Python's simplicity and low barrier to entry, but I say that as someone who knows little about Go.
- hellrich 13y agoTry Groovy! def foos = [ new Foo(2), new Foo(4) ]
- dkarl 13y agoI've been writing a lot of Groovy recently, and it feels like Scala without type checking. That's not the worst thing in the world, I'd rather just use Scala. With Groovy, I get a lot of the expressiveness of Scala, but the lack of static type checking combined with Groovy doing its best to be magical is a recipe for bugs. For example, in Groovy, you can overload methods accidentally without a warning, which can create a hell of a surprise when somebody passes a null value. Rather than throw an error, Groovy dispatches the call to one of the methods even if neither one is more specific than the other. There's also this classic bug: def printOne(Collection c) { if (c.empty) { print("Collection is empty") } else { print(c.iterator().next()) } } Can you spot the bug? This code works for all Collections... except Maps. If c is a Map, Groovy translates c.empty to c.get("empty"). Constantly having to be on my toes to avoid stuff like that is a pain.
- auvrw 13y ago> import Data.Maybe > let maybe_use_haskell = [ Just 2, Just 4 ] also, in you could do your original example in a single line, List<T> ts = new List<T>(List.fromArray({T(2),T(4)})); even though it's still messier than something with type inference.
- tikhonj 13y agoOr, in Haskell, it could even just be foos = [2, 4] even the fact that the 2 and 4 refer to foos can be inferred, as long as Foo behaves like a number and you make it part of the Num typeclass. It's pretty cool! So, oddly enough, static typing can actually make your code less noisy rather than more.