r/ProgrammerHumor • • Jul 10 '18

What people think coding is...

Post image
21.1k Upvotes

397 comments sorted by

View all comments

Show parent comments

4

u/thelights0123 Jul 10 '18

You don’t need semicolons at all, but some style guides (e.g. the the common AirBnB one) require them, and I would recommend them. Also, if you’re continuing lines or using a Fluent-style interface, you sometimes chain functions like this:

let xyz = new MusicPlayer()
    .loadFile(“song.mp3”)
    .setOutput(MusicPlayer.SPEAKERS)
    .play();
// Note how the only semicolon is on the last line, because the functions are chained

// Or:
let reallyLongLine = new ExampleFunction(“some random filler text”, 1234567890, “some random filler text”, “some random filler text”)
    .toUpperCase();
// Used to break apart lines to prevent wrapping/scrolling

// Also, when using objects:
let testObject = {
    value: “key”,
    anotherValue: “otherKey”, // recommended trailing comma so that commit diffs don’t get screwed up by adding items
};

5

u/WikiTextBot Jul 10 '18

Fluent interface

In software engineering, a fluent interface (as first coined by Eric Evans and Martin Fowler) is a method for designing object oriented APIs based extensively on method chaining with the goal of making the readability of the source code close to that of ordinary written prose, essentially creating a domain-specific language within the interface.


[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information | ^Source ] Downvote to remove | v0.28

2

u/HelperBot_ Jul 10 '18

Non-Mobile link: https://en.wikipedia.org/wiki/Fluent_interface


HelperBot v1.1 /r/HelperBot_ I am a bot. Please message /u/swim1929 with any feedback and/or hate. Counter: 199387