11 ms·
Java for Python programmers
- amelius 10y agoThe 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 10y agoIt 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.
- nnq 10y agoNow I feel tempted to add a comment like "written by an inhabitant of planet Brainfuck, fluent in symbolic poetry, who later became a Javascript developer" to some code I've recently reviewed...
- mgkimsal 10y agoinherited 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 10y ago> 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 10y agoprobably 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).
- tyingq 10y agoTotally agree. And python->java might be a pretty big challenge in that space, especially if you aren't using an IDE that can autocomplete the crazy long/verbose (this.that.wow.foo.bar.argh) java libraries.
- reitanqild 10y agoFortunately all the three big are available as open source. The free IntelliJ edition is somewhat limited but perfectly usable for core Java. I personally prefer Netbeans but then again I choose Linux or even Windows over Mac so there goes my credibility ;-/
- tyingq 10y agoSure. It came to mind for me because I'm one of those that started with vi/vim, and using an IDE regularly would be a big change for me. Vi works fine for python, but I imagine it would be a pretty big barrier for java.
- reitanqild 10y agoI have heard of people who use it and I know you can/could use vim modes or even embedded vim in at least two of the three big ones but I never used it. You might know all this but for the benefit of thise who don't: I guess you think in another way in an IDE: often you don't replace text (unless you are specifically updating comments or strings) - you rename variables. Example: the IDE knows about scoping rules etc so even if someone adds a local variable that shadows a field (BAD) the IDE will understand and only rename one of them when I do a rename. For me I find the IDE is more than worth it. Keybindings are a bit different but can be adjusted so I rarely need to use mouse or touchpad. And with Netbeans at least, but I suspect all big three, regex search replace is there if I need it.
- collyw 10y agoI also think that writing idiomatic code is important. I have seen a few Python apps written in a Java style. It negates many of the benefits of using Python.
- humanrebar 10y ago> The problem with learning a new programming language lies not in learning a few language constructs I think that's true, but more for GC-based languages than ones that are used for systems programming. Rust, C++, and to a lesser extent C all require a lot of learning to know what not to do at the language level.
- rodorgas 10y ago"Why Learn Java? Why not C or C++? If you know Java learning C++ is easy." Really?
- hood_syntax 10y agoMaybe 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 10y agoC++ 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.
- hood_syntax 10y agoFair enough, I stand corrected.
- mistermann 10y agoIf FactoryFactories are so bad, why do Java and C# devs (even "smart" ones) still use them? Harder to decompose = more job security?
- humanrebar 10y agoI 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.
- jerven 10y ago
- Philipp__ 10y agoAfter 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 10y agoTry Rust or modern C++. Both are pretty expressive but still suited for systems programming.
- Philipp__ 10y agoModern C++ is there, eventually. Kinda picking up courage to dive into it deeper. And Rust looks amazing, cool and promising. This year I spent playing with functional programming. One of the goals for next is to do something more concrete in that field, and after that I think I will jump on Rust bandwagon.
- collyw 10y agoAs 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.
- mttjj 10y agoDoes 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 10y agoI 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.
- mistermann 10y agoA less labor intensive approach might be a youtube channel, I really liked this Python one: https://www.youtube.com/user/sentdex https://www.youtube.com/user/sentdex
- mttjj 10y agoBlog 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 10y agoyou could compare it with this java source: http://svn.apache.org/repos/asf/shiro/branches/2.0-api-design-changes/ http://svn.apache.org/repos/asf/shiro/branches/2.0-api-desig...
- Singletoned 10y agohttps://antrix.net/static/pages/python-for-java/online/ https://antrix.net/static/pages/python-for-java/online/ seemed quite good, but I didn't go into it in any depth because I already know Python.
- anondon 10y agoThe code samples are striking: they demonstrate how verbose Java can be, compared to Python!
- TurboHaskal 10y agoI'll trade verbosity for braces and no significant whitespace any day of the week.
- irb 10y agoSwitched 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 10y agoThese 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.
- lucb1e 10y agoIf you have enough blank lines, { or } work as well in vim. At least that's what I use. Thinking about it, I only use % for parenthesis I think.
- ldiracdelta 10y agoI'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.
- 10y ago
- sjclemmy 10y agoI 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!
- qwertyuiop924 10y agoI 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 10y agoBefore down-voting this poor soul: Hobbyist programmer, Schemer (although not smug about it, really), gamer, voracious reader, and highschool student.
- qwertyuiop924 10y agoI 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".
- ddorian43 10y agoMany of the 'big data' tools are in java. If you want to extend them or even just use them you'll need it(~hbase, apache samza, lucene/solr/elasticsearch etc)
- TurboHaskal 10y agoI 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 10y ago
- berntb 10y agoI 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 10y agoThe 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 10y agoI 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. :-) )
- Spivak 10y agoI 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 10y agoNo... it definitely has not.
- uh-0h 10y agopublic 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?