• Batman@lemmy.world
    link
    fedilink
    arrow-up
    23
    ·
    21 hours ago

    My inner mathematician respects Java. The first step in any problem is defining your universe

  • lurklurk@lemmy.world
    link
    fedilink
    arrow-up
    24
    arrow-down
    2
    ·
    22 hours ago

    Hello World

    30 minutes of boilerplate

    writing imports

    $ cat <<EOF > Hello.java
    public class Hello {
      public static void main(String args[]) {
        System.out.println("Hello world!");
      }
    }
    EOF
    $ java Hello.java
    Hello world!
    

    ok

    • MooseTheDog@lemmy.world
      link
      fedilink
      arrow-up
      22
      arrow-down
      4
      ·
      22 hours ago

      Welcome to java, we have a couple unconventional ways of doing things, but overall I’m like every other mainstream oo language.

      People: AHH! Scary!

      Welcome to python. your knowledge of me wont help you elsewhere as my syntax is purposefully obtuse and unique. Forget about semicolons, one missed space and your code is as worthless as you after learning this language.

      People: Hello based department

      • Classy@sh.itjust.works
        link
        fedilink
        arrow-up
        7
        ·
        21 hours ago

        Oh my god I got fucked by a python script once because of a single space. It took forever to figure out what went wrong

        • TonyOstrich@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          11 hours ago

          I refuse to code in Python without a really good IDE and linting like PyCharm. When using PyCharm it’s very rare I have issues like this, because it catches them in one way or another, but I notice it catches those kinds of issues a lot when I’m coding soooooooo…

          I have also setup the IDE to specifically color code comments like

          ’ # End If and ’ # Next

          in the same style as their beginning statements as I find it much easier to visually scam through code when they are present.

      • JackbyDev@programming.dev
        link
        fedilink
        English
        arrow-up
        3
        ·
        edit-2
        18 hours ago

        **kwargs

        “No, I don’t use type annotations because they don’t actually do anything. In fact I purposefully give this parameter different types for different behaviors. How is that confusing?”

      • lurklurk@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        22 hours ago

        Python has its drawbacks but it also has a pretty useful standard library so as a language for small scripts, one can do much worse

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      5
      ·
      18 hours ago

      This is getting a little better nowadays.

      > cat Hello.java
      void main() {
          System.out.println("Hello, World!");
      }
      > java --enable-preview Hello.java
      Hello, World!
      

      Things to notice:

      1. No compilation step.
      2. No class declaration.
      3. Main method is not public static
      4. No String[] args.

      This still uses preview features though. However, like you demonstrated already, compilation is no longer a required step for simplistic programs like this.

      • Valmond@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        5 hours ago

        System.base.stuff.output.out.printfunctions.println

        Or so it felt every time you wanted to dump something into the console…

      • مهما طال الليل@lemm.ee
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        10 hours ago

        Main method is not public static

        It must be somewhere under the hood. Otherwise, it wont be callable and it would require an instance of an object to call. Unless the object here is the Java environment?

        No String[] args

        They are just optional I’m sure, like C and C++. You still need them to read command line arguments.

        All in all, these syntax improvements are welcome. I already moved on to Kotlin for Android development though.

        • JackbyDev@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          9 hours ago

          Main method is not public static

          It must be somewhere under the hood. Otherwise, it wont be callable and it would require an instance of an object to call. Unless the object here is the Java environment?

          No. From JEP-445:

          If an unnamed class has an instance main method rather than a static main method then launching it is equivalent to the following, which employs the existing anonymous class declaration construct:

          new Object() {
              // the unnamed class's body
          }.main();
          

          No String[] args

          They are just optional I’m sure, like C and C++. You still need them to read command line arguments.

          Without the preview feature enabled, it is not an optional part of the method signature. It specifically looks for a main(String[]) signature.

          • مهما طال الليل@lemm.ee
            link
            fedilink
            arrow-up
            2
            arrow-down
            1
            ·
            9 hours ago

            I am not in the mood to read a technical document, but I don’t think the resulting binary/byte code should be different between the two “hello world” programs. But then again, why not?

            Without the preview feature enabled, it is not an optional part of the method signature. It specifically looks for a main(String[]) signature.

            Ah ha! So that’s what’s going on here. They almost got it right. They had the potential to make a lot of the boilerplate optional or implicit under relevant circumstances, but instead the language has two explicit switchable modes.

            Can I write a Java application in “preview feature”?

            • JackbyDev@programming.dev
              link
              fedilink
              English
              arrow-up
              3
              ·
              edit-2
              8 hours ago

              I mentioned this uses preview features twice in the first comment regarding this, so I don’t know why you’re "ah ha"ing. Also you don’t need to read the technical document, I’ve quoted the entirety of the relevant text. I provided it as a citation.

              You seem confused about preview features. It’s not a switchable mode to reduce boiler plate. I find the name very clear, but here is more information. From JEP-12

              A preview feature is a new feature of the Java language, Java Virtual Machine, or Java SE API that is fully specified, fully implemented, and yet impermanent. It is available in a JDK feature release to provoke developer feedback based on real world use; this may lead to it becoming permanent in a future Java SE Platform.

              As an example, JDK 17 added pattern matching for switch statements as a preview, and by JDK 21 it was added as a full fledged feature that doesn’t require usage of the enable preview flag. Presumably in some future release of Java this feature will not require the usage of a flag.

              • مهما طال الليل@lemm.ee
                link
                fedilink
                arrow-up
                1
                ·
                edit-2
                8 hours ago

                It is pretty late for me. Sorry. And thank you for your patience. Repeating it three times helped.

                I will be interesting to find out if the resulting binary is the same or not and what’s possible once it matured.

                • JackbyDev@programming.dev
                  link
                  fedilink
                  English
                  arrow-up
                  2
                  ·
                  8 hours ago

                  Yes, because it’s genuinely not a static method. It’s an instance method. Also the signature is different. It’s not some sort of mere syntactic trick that translates void main() to public static void main(String[] args).

      • cashew@lemmy.world
        link
        fedilink
        arrow-up
        3
        arrow-down
        1
        ·
        edit-2
        15 hours ago

        Microsoft Java is a one-liner these days.

        > cat program.cs
        Console.WriteLine("Hello, World!");
        > dotnet run
        Hello, World!
        
    • meowMix2525@lemm.ee
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      21 hours ago

      I got the impression they skipped the hello world cause it was too easy and they wanted to get right to writing their app, so they moved on to more advanced stuff without having a real grasp of the basics

  • kerrigan778@lemmy.world
    link
    fedilink
    arrow-up
    6
    arrow-down
    1
    ·
    19 hours ago

    Java is terrible and I hated it but I feel like this stuff is not why, this mostly just seems like stuff that most powerful object oriented languages do.

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      6
      arrow-down
      2
      ·
      18 hours ago

      Java is amazing and I love it, and I agree that this is not really a good list of problems. (Not that I expect green texts to be well thought out, rational, real, fair, or anything other than hyperbolic rants lol.) There are good reasons to critique it and the ways people use it, but this isn’t it.

      Particularly funny is the one about race conditions. That’s something you’d have to deal with in any sort of multi threaded environment.

      • shastaxc@lemm.ee
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        12 hours ago

        Maybe they got confused and assumed it would run on a different cpu? Is there another language that does it that way? No, now I’m confusing myself.

        • JackbyDev@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          8 hours ago

          Various languages have various features to make multi threading/concurrent programming easier. Without knowing what language the green text is fanboying for instead of Java it’s hard to know what their specific gripe is. Supporting true multi threading out of the box has always been a priority of Java so I don’t know what they’re complaining about. Generally languages that people praise over Java like Python and JavaScript do not feature true multi threading. (Although Python is getting closer or there now that the GIL is optional.)

  • yamanii@lemmy.world
    link
    fedilink
    arrow-up
    8
    arrow-down
    2
    ·
    20 hours ago

    I still think Java is good for teaching newbies precisely because it will throw an error quickly if they are doing it wrong.

  • AusatKeyboardPremi@lemmy.world
    link
    fedilink
    arrow-up
    39
    arrow-down
    3
    ·
    1 day ago

    I might have agreed a decade or two ago, when I knew no better. But today, I find the tribalism surrounding programming languages comical.

    I don’t particularly like Java, but I use it because it pays the bills. Similarly, I use C++ (which I prefer) when my work requires it.

    • SorteKanin@feddit.dk
      link
      fedilink
      arrow-up
      33
      arrow-down
      1
      ·
      1 day ago

      I don’t particularly like Java, but I use it because it pays the bills. Similarly, I use C++ (which I prefer) when my work requires it.

      I mean, anon is not arguing against that. They’re saying the language is shit regardless of how much it is used in business. I don’t think they are entirely wrong.

    • frayedpickles@lemmy.cafe
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      7
      ·
      23 hours ago

      Tell us more ancient one, your heroic tale of “giving up against the endless weight of capitalism” is fascinating.

      • lurklurk@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        22 hours ago

        “giving up against the endless weight of capitalism”

        We just call it “having a job” nowadays

      • AusatKeyboardPremi@lemmy.world
        link
        fedilink
        arrow-up
        5
        ·
        22 hours ago

        Love the dramatics.

        This ancient one has learned the art of pragmatism. A little time in the trenches of enterprise development can do that – turn passionate ideals into practical choices.

        Some days it’s C++, some days it’s Java, Python and so on. In the end, the code compiles, and the ancient one get paid.

  • Ginny [they/she]@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    148
    arrow-down
    1
    ·
    2 days ago

    I also think Java is shit, but if you manage to get a NullPointerException while writing a hello world program, maybe anon is just not cut out for computers?

  • arc@lemm.ee
    link
    fedilink
    arrow-up
    8
    arrow-down
    5
    ·
    19 hours ago

    Could be worse, could be programming Javascript (or Typescript).

    • jol@discuss.tchncs.de
      link
      fedilink
      arrow-up
      7
      ·
      17 hours ago

      An text file with a <script> block and nothing else, containing a console log, is all you need. You already have all the boilerplate to run it in any computer. No extra dependencies, no installing anything. Literally just a notes editor app. This is a valid HTML file:

      <script>
      console.log("Hello World")
      </script>
      
      • Lysergid@lemmy.ml
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        13 hours ago

        I think you forgot to pollyfill your console.log and now you have some error in some script in some callback

    • Seeders@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      1
      ·
      edit-2
      14 hours ago

      I love javascript. Shit. Just. Works.

      Even if you, the programmer, are a complete fucking moron, by god javascript will try to make your program run as long as possible.

        • Malfeasant@lemm.ee
          link
          fedilink
          arrow-up
          5
          ·
          21 hours ago

          Some of us try to understand what we’re doing, rather than just copy/paste. It’s easy to discount how difficult learning the basics of something is when you’re already past it.

        • sugar_in_your_tea@sh.itjust.works
          link
          fedilink
          arrow-up
          3
          arrow-down
          2
          ·
          edit-2
          19 hours ago

          And most IDEs will autogenerate it for you.

          That said, I think it highlights everything I hate about Java:

          public class MyClass {

          Why does it need to be a class? I’m not constructing anything?

          public static void main(String[] args) {

          Why is this a method? It should be a top-level function. Also, in most cases, I don’t care about the arguments, so those should be left out.

          System.out.println(“Hello world!”);

          Excuse me, what? Where did System come from, and why does it have an “out” static member? Also, how would I format it if I felt so inclined? So many questions.

          And here are examples from languages I prefer:

          C:

          #include “stdio.h”

          Ok, makes sense, I start with nothing.

          int main() {

          Makes sense that we’d have an entrypoint.

          printf(“Hello world”);

          Again, pretty simple.

          Python:

          print(“Hello world”)

          Ok, Python cheats.

          Rust:

          fn main() {

          Ooh, entrypoint.

          println!(“Hello world”);

          I have to understand macros enough to realize this is special, but that’s it.

          In C, Python, and Rust, complexity starts later, whereas Java shoves it down your throat.

      • babybus@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        4
        arrow-down
        2
        ·
        22 hours ago

        Thank you. If you bothered to read a 5 minutes tutorial instead of posting to 4chan, you could also reach this level of knowledge.

        • pinkystew@reddthat.com
          link
          fedilink
          English
          arrow-up
          3
          arrow-down
          1
          ·
          edit-2
          21 hours ago

          Don’t be mad, you’re the one that commented lol. It’s like you’re choosing to be upset

          • babybus@sh.itjust.works
            link
            fedilink
            English
            arrow-up
            2
            arrow-down
            2
            ·
            20 hours ago

            I thanked you for your reply and suggested reading a tutorial. How does that make me mad and upset? You’re acting weird.

  • _____@lemm.ee
    link
    fedilink
    English
    arrow-up
    35
    arrow-down
    6
    ·
    1 day ago

    C# masterrace and I’m tired of pretending it’s not

    • EnderMB@lemmy.world
      link
      fedilink
      arrow-up
      5
      arrow-down
      1
      ·
      1 day ago

      After close to two decades of programming, C# is still the best language I’ve used. While some of the newer features seem a bit weird, I’d say it’s one of the few languages that has never got in the way and has just let me write code that made sense. Even with all the improvements Java has made over the years it’s still nowhere near as good as what C# was like maybe 15 years ago.

      The same goes for everyone’s other “fav” language, Python. Ruby has been a better beginner scripting language than Python for many years, and while Rails is definitely a ghetto, as a language Ruby is great at teaching great programming fundamentals.

    • drake@lemmy.sdf.org
      link
      fedilink
      arrow-up
      5
      ·
      1 day ago

      C# is pretty good generally - I know it far better than any other and it pays my bills! - but it certainly has its weak points. Particularly around the newer features, a lot of them feel really rushed and just kind of shitty.

      The one I hate the most is the whole “nullable” pattern. It’s a total mess. Having to mark up files as #nullable enable, having to mark methods with a bunch of attributes, and the way that it works differently if it’s a value type or a reference type, it’s just so half-baked.

      If you spend some time with a more modern language like Rust or Swift then you’ll quickly start to notice C#’s weaknesses.

      • KubeRoot@discuss.tchncs.de
        link
        fedilink
        English
        arrow-up
        1
        ·
        23 hours ago

        I feel like you’re doing something wrong with the nullables… I’m pretty sure you don’t need to mark up files, you can just enable it on the whole project? I’m not sure about the attributes, you might have a point there, but it just makes sense for value vs reference types IMO, since value types are already implicitly different in terms of nullability.

        But yeah, I can imagine it’s half-baked, since nullable reference types (that’s the name, previously reference types were just nullable by default with no extra features) are a more recent addition to the language, one that wasn’t built with them in mind.

        • drake@lemmy.sdf.org
          link
          fedilink
          arrow-up
          1
          ·
          19 hours ago

          If you create a new project from scratch, yes, you can enable it project-wide. If you have a project which has a bunch of code predates nullable reference types, and you enable it project wide, you’ll have a billion warnings about it. Also, they’re warnings and not errors by default, which just encourages developers to either ignore or suppress them.

          So the reality is that you need to remember when you’re making new classes to add the attribute, and then deal with external stuff - which isn’t always clearly marked whether it’s nullable or not unless it’s using attributes, by the way… just such a total mess.

          They should have just gone with something more like Rust’s “Option” type. Would have been clearer for codebases that have to deal with a mix. They also could have clearly and decisively deprecated non-nullable reference types and just told people they were going to remove support in some future version so we could all migrate to them properly like we’ve done for .NET Core/.NET 5+.

    • rekabis@lemmy.ca
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      1 day ago

      C# has had string interpolation for, what - nearly a decade, now? It arrived with C# v6, which was released in 2015.

      Meanwhile Java just pulled their implementation out of the latest beta earlier this year because they couldn’t get it to work right.

      Don’t know about you, but I think that Java is largely resting on its laurels as of late. That the only real reason to go for it is it’s third-party library system, and not much more.

    • sugar_in_your_tea@sh.itjust.works
      link
      fedilink
      arrow-up
      2
      arrow-down
      3
      ·
      edit-2
      19 hours ago

      C# is nicer Java, but I think it’s still fundamentally a poor language.

      Rust master race:

      fn main() {
          println!("Hello world!");
      }
      

      Unfortunately, the time you save typing you’ll spend compiling, so there’s that…

    • Mr_Blott@feddit.uk
      link
      fedilink
      arrow-up
      6
      arrow-down
      2
      ·
      1 day ago

      Really want to go to La Scala one day but I looked it up and the tickets are like 500 euros. An eclipse is much cheaper