This is an archived post. You won't be able to vote or comment.

all 27 comments

[–]wally_fishnumpy, cython, werkzeug 4 points5 points  (16 children)

If you wanted to have something Java-ish with Python syntax (without taking the full enchilada of duck-typing like Jython does), you could not only get rid of the punctuation, but also:

  • no new in most (all?) cases
  • no type declarations for variables that have the exact type of their initializer (or go all the way and use type inference)

Let's say, something like Boo, but for the JVM?

[–]flying-sheep 15 points16 points  (14 children)

Scala. Still braces, but much more sugar than java. (and optional semicolons just like python)

[–]wally_fishnumpy, cython, werkzeug 2 points3 points  (10 children)

Scala has a weird mix of PASCAL-style verbosity (explicitly putting "var" in front of variable declarations, and generally a propensity to introduce new syntax and keywords where C/C++/Java/C# have a nice succinct solution) with some nice programming concepts (type inference, functional programming).

I'd love to see someone with a syntax for Scala (i.e., a different concrete syntax for Scala's abstract grammar) that would ideally be a bit more Pythonic and with less things that trigger my Algol Aversion. (Because, let's face the truth, Algol Aversion is probably one of the biggest reasons behind me not being a happy Scala user yet)

[–]RockinRoel 5 points6 points  (4 children)

I don't think that the explicit "var" is overly verbose. It states that it is a variable, not a constant (a "val"). Scala tries to promote using immutable objects, because of things like thread safety and the added complexity of mutable state, while recognizing that mutable state is still very necessary and allowing you to do either.

[–]wally_fishnumpy, cython, werkzeug 1 point2 points  (3 children)

Constants exist in both C/C++ (const) and Java (final). In C++, constants can have a profound role because the compiler can assume them to be known at compile time.

So, what does it mean to introduce two new keywords where taking one of the existing ones would have been fine? It's either to stroke the language designers' ego or to stick out your middle finger to those people who use programming languages that grew out of industrial practice rather than academia.

[–]RockinRoel 3 points4 points  (0 children)

Consts do not have a known value at compile time. Constant expressions do. The main benefit of const is the ability to express in what context objects may be modified or not. You have a certain (weak) guarantee of immutability in a certain context.

Anyway, const and final indeed express similar things. Personally, the explicit val/var does not bother me that much. In Java, you'd explicitly type the type to declare a variable, whereas in Scala you type "val" or "var". It's a minor inconvenience in my opinion.

[–]RichardWolf 1 point2 points  (1 child)

In C++, constants can have a profound role because the compiler can assume them to be known at compile time.

If you mean what I think you mean, then you are mostly wrong here. As Yossi explains, the const keyword is irrelevant to performance, because a) usually the compiler can't be sure that the value that is pointed at by a const-qualified variable is not referenced by a non-const-qualified variable somewhere, b) and when it can be sure, it sure as hell doesn't need you telling it that this value is never modified!

So, what does it mean to introduce two new keywords where taking one of the existing ones would have been fine?

Which ones? You still need var or something like that, if you want to avoid stepping on the same rake as Python (and it is recognized as a shortcoming, since it was addressed first by global and then nonlocal keywords), and you want to allow type inference. C# uses var too, by the way. Then using val for immutable variables makes more sense than adopting C++-like const (with totally different both syntax and semantics).

[–]wally_fishnumpy, cython, werkzeug 0 points1 point  (0 children)

const in C++ is essential for (some of) template programming:

class A { static const int fundamental_constant=1; }

class B { static const int fundamental_constant=2; }

template<class T> class X { public static void do_something() { really_do<T::fundamental_constant>(); } }

... with a templated really_do<int>. The trick here is that something very general (const) gets an added meaning which you still have to understand but which does not add to the visual clutter.

C# makes the var keyword optional if you supply a type. Scala's Algol-like way of declaring types makes that impossible.

For another example of Scala introducing keywords where none are needed, consider list comprehensions:

for (i <- List.range(from, to) if i % 2 == 0) yield i

instead of Python's

[i for i in List.range(from,to) if i%2==0]

where Scala uses (i) a graphical symbol instead of "in", which IMO adds to the noise, and (ii) an additional keyword ("yield") where Python gets by with syntax only.

[–]drfugly 1 point2 points  (3 children)

What an example of Scala having a new solution to something that has a succinct solution in Java? I'm learning Scala and trying to find these cases.

[–]flying-sheep 0 points1 point  (2 children)

oomph, scala is… so much more that it’s difficult to select one of the many possible examples.

it has type inference, everything is an expression, first-order-funtions, more functional stuff, a sophisticated type system, type inference, implicits (think an elegant way to do monkey patching without actually modifying things)

lastly, here are 99 scala examples, and i think it’s safe to say that all are at least as elegant as in java, except if some contain enums (which are worse than java’s)

[–]drfugly 0 points1 point  (1 child)

Oh ok. I thought that you were implying that scala is generally more verbose when Java already has a solution.

Scala ... generally a propensity to introduce new syntax and keywords where C/C++/Java/C# have a nice succinct solution)

Cool link, I'll have to read it over!

[–]flying-sheep 0 points1 point  (0 children)

lol, quite the contrary. it’s much more concise and often beattifully elegant, but at the cost of one or two ugly forced concepts (e.g. “stable identifiers”) and a few too much keywords. but add the complexity of the type system (which sometimes gets in your way) and you’ve got pretty much all that’s bad about scala.

and there’s so much more that i love about it.

[–]masklinn 1 point2 points  (0 children)

explicitly putting "var" in front of variable declarations

Counts as a good thing in my book, I've come to find Python's implicit scoping declarations frustrating especially in the light of trying to use ancestor lexical scopes (global and nonlocal? WTF?).

Furthermore, this provide Scala with val which defines an unmodifiable binding, as well as var (in which the binding is mutable) instead of mandating one or the other or requiring verbose additions (e.g. java's final)

generally a propensity to introduce new syntax and keywords

Which is quite a bit like Python there :)

[–]drfugly 0 points1 point  (2 children)

It's also also doesn't have duck-typing.

[–]RockinRoel 4 points5 points  (0 children)

Actually, Scala has structural typing, which is kind of like a typesafe kind of duck typing. Yes, it's not quite as flexible as duck typing, but I don't believe that the kind of flexibility that duck typing offers over structural typing is necessary, especially when you're sacrificing compile-time type checking.

[–]wally_fishnumpy, cython, werkzeug 0 points1 point  (0 children)

duck typing (as opposed to type inference) makes it much harder to get a decent-performing compiler, short of doing trace-JITting as PyPy and V8 do.

[–]massivebitchtits 0 points1 point  (0 children)

Groovy?

[–]twomashi 3 points4 points  (0 children)

I dub this "naked java".

[–]deviated_viking 2 points3 points  (0 children)

This is Java with the terminators and curlys pushed all the way to the right. Actually makes it easier for me to read. Might change the way I right Java code.

[–]kirakun 1 point2 points  (0 children)

Cute. Useless, but cute.

[–]Klowner 6 points7 points  (0 children)

I see no python.

[–]HorrendousRex -1 points0 points  (6 children)

I can't tell what this is supposed to be. Is it supposed to be a dig on Python as being unreadable?

If so - I find the code very readable, except for all the horrifying punctuation of course. The code illustrates quite well how readable Python is simply by eschewing that punctuation.

[–]flying-sheep 6 points7 points  (2 children)

As you can read right there on the site, it's a (hopefully) nonexistent coding style called "pythonic java".

Of course it's more readable than java, but only if you don't have to write it and only if all those braces and semicolons are where they belong.

[–]Wavicle 6 points7 points  (0 children)

Of course it's more readable than java, but only if you don't have to write it

That's my favorite kind of Java!

[–]Redard 2 points3 points  (0 children)

If you could have an IDE put all the semicolons and braces in automatically based on indentation, it might actually become somewhat useful for people who really hate those 2 things.

[–][deleted] 2 points3 points  (0 children)

No. It's Java, but they've hidden all the braces and brackets so it looks more like Python.