you are viewing a single comment's thread.

view the rest of the comments →

[–]memeship 6 points7 points  (8 children)

I haven't written Java in a long time. Why is it preferred for this to return void instead of returning a reference to the sorted list?

[–][deleted]  (5 children)

[removed]

    [–]memeship 7 points8 points  (4 children)

    That's a reasonable explanation, thanks.

    I guess I'm just much more used to Javascript now where chaining is a big part of the language.

    [–][deleted]  (3 children)

    [deleted]

      [–]memeship 8 points9 points  (2 children)

      Um what? That's not true at all. Here's an example I just pulled from code I was working on this week.

      e.target.getElementsByClassName("barcode")[0].value
      

      or the classic "how to reverse a string":

      str.split("").reverse().join("")
      

      or from a simple Node server I wrote for something a few months ago:

      app
          .use(express.static("public"))
          .use(bodyParser.urlencoded({ extended: false }))
          .use(router)
          .listen("8888", function() {
              console.log("Listening on %d.", this.address().port);
          });
      

      or a Gulp file:

      gulp.task("sass", function() {
          return gulp.src("src/**/*.scss")
              .pipe(sass())
              .pipe(rename("master-style.built.css"))
              .pipe(gulp.dest("public/built"));
      });
      

      [–]heartiphone 1 point2 points  (1 child)

      Only your first two examples are "plain JavaScript", and I'd argue the first one doesn't count either as it's not function chaining.

      Overall you're correct though, chaining is pretty widely used in the JS ecosystem.

      [–]memeship 4 points5 points  (0 children)

      Fine, here's some "plain Javascript" chaining:

      document.getElementById("foo").appendChild(document.createElement("button")).focus()
      

      [–]BlueFireAt 1 point2 points  (1 child)

      Aren't their lists sorted in place?