Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
 TadoTheRustacean   ( @TadoTheRustacean@programming.dev )  to Programmer Humor@programming.devEnglish · 2 years ago

thisIsGoingToBeASeriousDebate

programming.dev

message-square
33
link
fedilink
200

thisIsGoingToBeASeriousDebate

programming.dev

 TadoTheRustacean   ( @TadoTheRustacean@programming.dev )  to Programmer Humor@programming.devEnglish · 2 years ago
message-square
33
link
fedilink
alert-triangle
You must log in or # to comment.
  •  dauerstaender   ( @dauerstaender@feddit.de ) 
    link
    fedilink
    arrow-up
    34
    ·
    2 years ago

    Unsafe block detected. Extermination initiated. There is no hiding from memory safety!

  •  30p87   ( @30p87@feddit.de ) 
    link
    fedilink
    arrow-up
    33
    ·
    2 years ago

    Personally,

    echo Hello World!
    
    •  pranaless   ( @pranaless@beehaw.org ) 
      link
      fedilink
      arrow-up
      31
      ·
      2 years ago
      use std::process::Command;
      
      fn main() {
          Command::new("sh")
              .arg("-c")
              .arg("echo Hello World!")
              .spawn()
              .unwrap();
      }
      

      Like this?

      •  30p87   ( @30p87@feddit.de ) 
        link
        fedilink
        arrow-up
        10
        ·
        2 years ago

        No, more like

        use std::process::Command; fn main() { Command::new("sh").arg("-c").arg("echo Hello World!").spawn().unwrap(); }
        

        .
        Just a little bit shorter, as it seems /s

        •  funkajunk   ( @funkajunk@lemm.ee ) 
          link
          fedilink
          English
          arrow-up
          8
          ·
          2 years ago

          I just fucking threw up

          •  30p87   ( @30p87@feddit.de ) 
            link
            fedilink
            arrow-up
            6
            ·
            2 years ago

            I did too. Multiple times in fact, I had to look at the other Rust code!

        •  TadoTheRustacean   ( @TadoTheRustacean@programming.dev ) OP
          link
          fedilink
          arrow-up
          2
          ·
          2 years ago

          Isn’t echo a shell builtin?

          •  pranaless   ( @pranaless@beehaw.org ) 
            link
            fedilink
            arrow-up
            1
            ·
            2 years ago

            Yes and no. While coreutils does provide an echo binary, shells also have a built-in for optimisation purposes.

            At first I had the code calling the binary directly, but then changed it to spawning a shell (and so using the builtin). It’s very cursed either way.

  •  r00ty   ( @r00ty@kbin.life ) 
    link
    fedilink
    arrow-up
    14
    ·
    2 years ago

    Or, you could just go the whole hog. Create your own simple CPU emulator, design a basic 8bitesque CPU, give it an output port that is the console, and load up some basic ASM to cycle through Hello World to the console port.

  •  umbraroze   ( @umbraroze@kbin.social ) 
    link
    fedilink
    arrow-up
    12
    ·
    2 years ago

    Oh you fancy PC people and your fancy syscall instruction.

    I still don’t know why I could remember jsr $ab1e. I didn’t even write that much assembly.

    •  AVincentInSpace   ( @AVincentInSpace@pawb.social ) 
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 years ago

      That looks like a 6502 instruction. What system is it from?

  •  Speiser0   ( @Speiser0@feddit.de ) 
    link
    fedilink
    arrow-up
    12
    ·
    edit-2
    2 years ago

    Definitely left. Right one won’t be optimized. (And there are so many some mistakes in your inline asm…)

    •  TadoTheRustacean   ( @TadoTheRustacean@programming.dev ) OP
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      What mistakes?

      •  Speiser0   ( @Speiser0@feddit.de ) 
        link
        fedilink
        arrow-up
        5
        ·
        2 years ago

        Mostly the missing listing of clobbered registers. Other than that it’s mostly just that you’re doing useless things, like manually putting the stuff into the registers instead of letting the compiler do it, and the useless push and pop. And the loop is obviously not needed and would hurt performance if you do every write like that.

        asm!(
        "syscall",
        in("rax") 1,
        in("rdi") 1,
        in("rsi") text_ptr,
        in("rdx") text_size,
        
        )
        

        (“so many” was inappropriate, sorry.)

        •  TadoTheRustacean   ( @TadoTheRustacean@programming.dev ) OP
          link
          fedilink
          arrow-up
          1
          ·
          2 years ago

          I am hopeless at getting the text_ptr simpler than i64::from_str_radix(&format!(“{:p}”, my_string)[2…], 16).unwrap(); How can i get it the normal way?

          •  Speiser0   ( @Speiser0@feddit.de ) 
            link
            fedilink
            arrow-up
            2
            ·
            2 years ago

            Just use str::as_ptr().

            Here’s an example (disclaimer: I haven’t used inline asm in rust before, expect issues): https://godbolt.org/z/sczYGe96f

  •  starman   ( @starman@programming.dev ) 
    link
    fedilink
    English
    arrow-up
    9
    ·
    2 years ago

    Console.WriteLine("Hello World!");

  •  Arthur Besse   ( @cypherpunks@lemmy.ml ) 
    link
    fedilink
    arrow-up
    8
    ·
    2 years ago

    https://www.gnu.org/fun/jokes/helloworld.html

  •  lugal   ( @lugal@sopuli.xyz ) 
    link
    fedilink
    arrow-up
    8
    ·
    2 years ago
    def main(): 
        print("Hello world") 
    
  •  nonearther   ( @nonearther@lemmy.ml ) 
    link
    fedilink
    English
    arrow-up
    7
    ·
    2 years ago

    console.log(“Hello World!”)

  •  raubarno   ( @raubarno@beehaw.org ) 
    link
    fedilink
    arrow-up
    4
    ·
    2 years ago

    Why do you call write() for every char? You can always just pass a pointer with its length.

    •  TadoTheRustacean   ( @TadoTheRustacean@programming.dev ) OP
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      I am not skilled enough to do that ngl

  •  DNOS   ( @DNOS@reddthat.com ) 
    link
    fedilink
    arrow-up
    4
    ·
    2 years ago

    Ec Emm this side is the best one …

    ++++++++[< +++++++++>-]<. ++++[<+++++++>-]<+. +++++++… +++.

    ++++++[<+++++++>-]<++. ------------. ++++++[<+++++++++>-]<+. <. +++. ------. --------.

    ++++[<++++++++>-]<+.

  •  Cwilliams   ( @Cwilliams@beehaw.org ) 
    link
    fedilink
    arrow-up
    3
    ·
    2 years ago

    I thought the whole point of rust macros was to abstract away the scary asm at zero cost!

  •  MonkderZweite   ( @MonkderZweite@feddit.ch ) 
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    2 years ago

    plan 9 cat vs GNU longcat meme

    edit: reddit image linking is broken?

    •  AMDIsOurLord   ( @AMDIsOurLord@lemmy.ml ) 
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      2 years ago

      deleted by creator

      •  MonkderZweite   ( @MonkderZweite@feddit.ch ) 
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        Of course, not always is shorter better.

    •  rhpp   ( @rhpp@programming.dev ) 
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      reddit image linking is broken?

      Well you didn’t link to a reddit image, you linked to Google image search result page which is not an image.

      •  rhpp   ( @rhpp@programming.dev ) 
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        deleted by creator

      •  MonkderZweite   ( @MonkderZweite@feddit.ch ) 
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        I did that because the image didn’t show in reddt.

        •  rhpp   ( @rhpp@programming.dev ) 
          link
          fedilink
          arrow-up
          2
          ·
          2 years ago

          Looks like you need to insert the raw image link, not Reddit’s media wrapper link.

          plan 9 cat vs GNU longcat meme

          •  MonkderZweite   ( @MonkderZweite@feddit.ch ) 
            link
            fedilink
            arrow-up
            1
            ·
            2 years ago

            Oh, so it’s only my browser setup that doesn’t show it.

  •  Arthur Besse   ( @cypherpunks@lemmy.ml ) 
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    2 years ago

    dc <<<'10435358689859 70511561 11297399 23 5 3 2 ******P'

    note: lemmy’s “smart quotes” vs its input sanitization required me to code-format the second half of that line (and not the first half) to make it copy+paste runnable.

  •  verstra   ( @verstra@programming.dev ) 
    link
    fedilink
    arrow-up
    2
    ·
    2 years ago

    Camel case?

    this_is_not_going_to_be_a_serious_debate

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 177 users / day
  • 2.26K users / week
  • 4.47K users / month
  • 8.61K users / 6 months
  • 447 local subscribers
  • 27.7K subscribers
  • 1.14K Posts
  • 18.4K Comments
  • Modlog
  • mods:
  •  Feyter   ( @Feyter@programming.dev ) 
  •  adr1an   ( @anzo@programming.dev ) 
  •  BurningTurtle   ( @BurningTurtle@programming.dev ) 
  •  Pierre-Yves Lapersonne   ( @pylapp@programming.dev ) 
  • BE: 0.19.13
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code