294

I used to code in Python a lot. Now, for work reasons, I code in Java. The projects I do are rather small, and possibly Python would work better, but there are valid non-engineering reasons to use Java (I can't go into details).

Java syntax is no issue; it is just another language. But apart from the syntax, Java has a culture, a set of development methods, and practices that is considered "correct". And for now I am completely failing to "grok" that culture. So I would really appreciate explanations or pointers in the right direction.

A minimal complete example is available in a Stack Overflow question that I started: https://stackoverflow.com/questions/43619566/returning-a-result-with-several-values-the-java-way/43620339

I have a task - parse (from a single string) and handle a set of three values. In Python it is a one-liner (tuple), in Pascal or C a 5-liner record/struct.

According to the answers, the equivalent of a struct is available in Java syntax and a triple is available in a widely-used Apache library - yet the "correct" way of doing it is actually by creating a separate class for the value, complete with getters and setters. Someone was very kind to provide a complete example. It was 47 lines of code (well, some of these lines were blanks).

I understand that a huge development community is likely not "wrong". So this is a problem with my understanding.

Python practices optimize for readability (which, in that philosophy, leads to maintainability) and after that, development speed. C practices optimize for resource usage. What do Java practices optimize for? My best guess is scalability (everything should be in a state ready for a millions-LOC project), but it is a very weak guess.

  • 1
    wont answer the technical aspects of the question but still in context : https://softwareengineering.stackexchange.com/a/63145/13899 – Newtopian Apr 26 '17 at 13:17
  • 74
  • 2
  • Relevant is the essay "Object Oriented Programming is an expensive disaster which must end" -- http://www.smashcompany.com/technology/object-oriented-programming-is-an-expensive-disaster-which-must-end – LRK9 May 01 '17 at 18:09
  • 3
    Here is what I think is the right answer. You aren't groking Java because you think about programming like a sysadmin, not a programmer. To you, software is something that you use to achieve a particular task in the most expedient manner. I've been writing Java code for 20 years, and some of the projects I've worked on have take a team of 20, 2 years to achieve. Java is not a replacement for Python nor vice versa. They both do their jobs, but their jobs are entirely different. – Richard May 01 '17 at 23:36
  • IMO the point of all those formalisms of Java is mainly to ensure the correctness and robustness of code, as well as a rigid, unified standard for the whole team to adhere to. That's what happens in huge enterprises. The development process is extremely detailed and takes a lot of time, but they can afford it. Now whether you and I as developers would like such practices/think of it as worth the effort is another matter. – xji May 02 '17 at 11:25
  • 2
    The reason that Java is the de-facto standard is because it is simply right. It was created right, first time, by serious people who had beards before beards were fashionable. If you're used to knocking up shell scripts to manipulate files, Java seems intolerably bloated. But if you want to create a dual redundant server cluster capable of serving 50M people a day, backed by clustered redis caching, 3 billing systems and a 20M pound oracle database cluster.. You're not going to be using python, even if accessing the database in Python is 25 lines less code. – Richard May 02 '17 at 12:48
  • 1
    I'm going to say the simple answer is because of Eclipse. The two routes the language could have taken were to move towards more concision, or build tools to manage the verbosity. Java went with managing the verbosity. None of it is necessary, and in fact there are safer, stronger, far more terse systems.

    It's not marketed to developers either. It's marketed to enterprises. As such it does not have to be appealing to developers. If you do think Java is appealing as a developer, then I'm sorry, but you're either suffering from Stockholm Syndrome, or you've somehow never used anything better.

    – Steven Armstrong May 05 '17 at 03:33
  • Splitting a string is not parsing, it is tokenising. 2) Java could split the string in one line as well with str.split(..) 3) Parsing is about information not data, it includes an element of context and meaning. 4) Tuples come in many sizes (N-Tuples) creating a specific class for the context promotes type safety. 4) Python is optimised for brevity not meaning; in the small those are the same; in the large not so much.
  • – Martin Spamer Jun 13 '19 at 17:05