
Java for Python programmers - gh1
http://interactivepython.org/courselib/static/java4python/Java4Python.html
======
amelius
The problem with learning a new programming language lies not in learning a
few language constructs; it lies in getting to know the libraries and the
whole ecosystem around the language.

~~~
RyanHamilton
It is amusing though when you inherit code written in language A by someone
that is actually fluent in language B. Sometimes it's not at all idiomatic and
is in fact a recreation from the other language. I enjoy trying to guess what
language (or planet) the person is writing code from.

~~~
mgkimsal
inherited a grails codebase from a team who mostly hated groovy/java, and
tried to recreate rails/ruby in almost all the code. all external supporting
libraries and tools were ruby, and it had more than a few "groovy sucks
because it's not ruby" comments scattered around. Apparently just the top CTO
guy there liked grails, started the project, brought on people, but they all
hated it. and built a massive monstrosity that was neither idiomatic ruby,
groovy or java. :/

~~~
vorg
> a team who mostly hated groovy/java

Sounds like they hated Java rather than specifically Apache Groovy, which is
really a scripting language _for_ systems already built with Java code.

~~~
mgkimsal
probably a bit of both, but the bulk of the code (grails code) was almost all
groovy, and there was enough complaints about how 'slow' groovy was that there
was some groovy-specific hate going on as well. Granted, especially then,
groovy wasn't the fastest around, but for most of what was being done, it
wasn't a bottleneck (and... _ruby_ at that point wouldn't have been any faster
- there was some prototypal stuff in ruby to try to make some processing
faster, and it wasn't).

------
Philipp__
After a lot of Pascal (had it in high school and first year of uni, wrote some
bigger CRUD apps in it, silly I know) and C, it was really hard for me to
adopt python. I just couldn't shake the feeling that I had to do everything
myself, (even though python provides you with everything you need, I end up
writing some function which with a bit of googling already exist as a part of
language), that I got from C and Pascal (where I had to write even my own text
parser for some apps I did). So I was bashing my head against the wall every
time I tried to use python. So in the end I failed and Java was next thing I
hit. It was cool. But it was interesting that after learning Java it was much
much more easier for me to adopt Python. It was weird in the beginning where
you have function for a lot of things, but Java seemed to have rewired
something in my head. ¯\\_(ツ)_/¯ after using Java my Python was much better.
Still not good enough in my opinion, as it is hard for me to wrap my mind
around some concepts that are different in Python, where you do not have to
type a lot, and things are pretty much done with using packages and functions
(external or internal API). It seems like a lot of alchemy and blackboxes to
me (python little less, but Javascript is totally like that). And I read a lot
of books, even some practical ones, wrote few smaller projects, but it always
blew my mind that I write ~100 line program in python, and exact same thing
would take me like few hundreds or even thousands in C. But I am mostly
interested in systems/OS programming so understand me...

~~~
adrianN
Try Rust or modern C++. Both are pretty expressive but still suited for
systems programming.

~~~
collyw
As a Python programmer who has been dabbling in Rust recently, it still seems
a lot more manual to me. Maybe I just need to learn more Rust, but my
impression is that as it is a low level language and as such you are expected
to think about a lot more things in Rust than Python.

~~~
qwertyuiop924
Exactly. That's sort of the point. It's still as systems language, unlike
Python. So you do have to think more.

~~~
erelde
Think more about the machine/platform not "think more" in absolute terms.

------
mttjj
Does anyone know of any resources like this to go the other way - Java to
Python? I know a minimal amount of Python but want to learn more. And I know
Java very very well. I feel like this learning style is perfect for me and
would help me understand Python a lot better.

~~~
Dowwie
I ported an alpha version of Apache Shiro to python. There was so much to
refactor. Even after three releases this year I have a sense that Java
patterns may linger, like a PTSD but from porting - a PTPD.

The project:
[http://yosaiproject.github.io/yosai](http://yosaiproject.github.io/yosai)

Would you read blog posts about porting Java to python if I wrote them? I was
considering applying to talk about this at PyCon.

~~~
mttjj
Blog posts like that might be interesting. I'm not really looking to port any
existing code over. Just kind of wanting to get my mind thinking in Python-
esque concepts coming from a Java background. Thanks for the link though I'll
browse through your project.

~~~
Dowwie
you could compare it with this java source:
[http://svn.apache.org/repos/asf/shiro/branches/2.0-api-
desig...](http://svn.apache.org/repos/asf/shiro/branches/2.0-api-design-
changes/)

------
rodorgas
"Why Learn Java? Why not C or C++? If you know Java learning C++ is easy."
Really?

~~~
hood_syntax
Maybe because Java is a more principled OO language? I'm not sure what he's
getting at either but the only skill difference is manual memory management
right? (although that certainly isn't overly intuitive it's easier in C++ than
C from what I've heard)

I don't use C++ so I could be way off base, just putting forth a possible
explanation

~~~
adrianN
C++ is completely different from Java unless you chose to write Java with C++
syntax. Modern C++ is heavy on using templates and static dispatch instead of
virtual calls and inheritance. The culture is very different as well; you
won't see many FactoryFactories in C++ code.

~~~
mistermann
If FactoryFactories are so bad, why do Java and C# devs (even "smart" ones)
still use them? Harder to decompose = more job security?

~~~
humanrebar
I think much of the problem with FactoryFactories is naming them
FactoryFactories. We don't call processes 'ProgramCounterContextCollections'.
The pattern isn't bad, in fact flavors of it (if you squint) are used
regularly even in low-level C systems code.

------
anondon
The code samples are striking: they demonstrate how verbose Java can be,
compared to Python!

~~~
TurboHaskal
I'll trade verbosity for braces and no significant whitespace any day of the
week.

~~~
irb
Switched from Java to Python as my main moneymaker several years go and I
still don't understand why some people have such a big problem with
significant whitespace.

You format your code anyway, right? So what's the difference if it actually
means something?

~~~
TurboHaskal
These people either work with very large codebases or have enough experience
to understand that the average developer is careless enough to risk safety
just for a little bit of convenience.

I'm personally keen on using % on vi or clicking on the braces for selecting
scope in Eclipse and ACME. I also find them aesthetically appealing much like
Lisp parenthesis.

~~~
ldiracdelta
I've seen a parallel in braced languages where the code spacing alignment was
out of whack with the actual blocks as denoted with bracing and then people
thought they were adding code to one block, but it was actually a parent
block. People seem to inherently use white space to determine block scope.

------
qwertyuiop924
I just have one question: Why?

Why, in this day and age, learn Java unless you absolutely must? (which you
probably will, at some point, but if you're lucky, maybe avoid it). It was a
pretty miserable language to begin with, and has since been surpassed in just
about every way.

If you're thinking about using Java for a project, you can probably use C,
Rust, or JS/Python/Ruby/etc. Hell, you could even use Haskell, ML, Lisp, or
Smalltalk, if you're that sort of person.

But don't use Java if you can avoid it. It will make you feel better, likely
improve your productivity, and make you stop wishing that you could commit
seppuku.

~~~
TurboHaskal
Before down-voting this poor soul:

    
    
      Hobbyist programmer, Schemer (although not smug about it, really), gamer, voracious reader, and highschool student.

~~~
qwertyuiop924
I did say _if you had to_.

In the industry, I can understand why you might have to learn it. I just don't
understand why you'd _want_ to.

But then, I never liked Java: maybe I just don't "get it".

~~~
TurboHaskal
I highly dislike Java as well but as a professional and somewhat pragmatic
programmer I'd be extremely wary of discouraging a fellow developer to learn
such a dominant language like Java.

Worry not, your Scheme kool-aid will fade out eventually.

~~~
qwertyuiop924
That's a fair criticism. Hell, I'll probably have to learn Java sooner or
later, like it or not.

>Worry not, your Scheme kool-aid will fade out eventually

It's not Kool-Aid. I can tell because I am still capable of criticising
Scheme, and am not in awe of it.

Scheme has a weak stdlib (which is both good and bad), its string handling is
painful at best, as srfi-13 doesn't provide a lot of common functionality, its
function names are painfully long (call-with-current-continuation. Really?
What would you call 'do' if you hadn't inherited it from maclisp? iterate-
over-variables-incrementing-until-condition?) Which matters a lot when your
whole language is made up of them, or things that look like them (how many
times do you want to type 'vector-ref'?). Scheme has no dynamic variables.
Chicken, my scheme of choice, and the most viable one for real work, lacks a
decent debugger. Gambit and Guile have good debuggers, but Guile is slow, and
Gambit has no libraries, so you can't get anything done. Scheme _still_
doesn't have a standard imperative macro system. And the SSC is still working
on R7RS-large, which will finally bring together a stdlib large enough to
write scheme portable across implementations without snapping and spending the
rest of your life in a corner, dribbling about syntax-rules.

I like scheme: it's both syntactically and semantically small, beautifully
clean, and even decent for some kinds of real work.

But it's not even close to perfect, or even ready for industry.

------
sjclemmy
I wish there was a Java for JavaScript programmers. I was looking for one the
other day, couldn't find it. There are plenty of JavaScript for Java devs!

------
uh-0h
public class Hello {

    
    
        public static void main(String[] args) {
           StringBuffer output = new StringBuffer();
           Process p;
    		try {
    			p = Runtime.getRuntime().exec("pwd");
    			p.waitFor();
    			java.io.BufferedReader reader =
                                new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()));
    
                            String line = "";
    			while ((line = reader.readLine())!= null) {
    				output.append(line + "\n");
    			}
    
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
            System.out.println(output.toString());
    
        }
    

}

/home/jobe/runs/jobe_AnIK6J

probably not a good sign....

Do python repls let you execute anything on the host?

------
Spivak
I only used Java when I was in school, has the standard changed to always use
the boxed type?

    
    
        for (Integer i = 0; i < 10; i++ ) {
            System.out.println(i);
        }

~~~
sk5t
No... it definitely has not.

------
berntb
I guess the real reason for a scripting language programmer to go Java is that
you want to use the JVM?

Otherwise, wouldn't it be simpler to just profile to find the slow places in
your existing code -- then rewrite those in C? You can use the scripting
language for most code, where it shines -- speed of development. And still get
a good speed of execution.

If you need even more speed (you wouldn't really get less memory usage!), then
sure... Java is one way to go for a Python/Ruby/Perl/PHP guy. But... when is
it the best choice?

~~~
tyingq
The reason could be for employment opportunities. Java is pretty pervasive in
non-tech Fortune 500 companies. It's easy to find Java openings, with decent
compensation, in cities with a low cost of living.

~~~
berntb
I had to think about this, which is a bit weird in itself.

My attitude is that I hope to choose at least one thing -- the stack or the
problem area. If I can do that, I should be quite happy.

To not want to leave a geographic location is of course valid choice --
probably often a healthier one than mine, but in this phase of my life, I
prioritize doing things I enjoy quite highly. (I would do Windows anyway, if
the money was right or I could do it from e.g. Japan. :-) )

