Code Formatting

Topic

Code Formatting

Topic Progress:

Text coding programmers like to argue that different coding styles are better than another, but keep in minds these are “guidelines.” We don’t mind if you go for a different set of rules to these, just that you code keeps to a consistent set of them.

Indent

Text coding programmers like to argue that different coding styles are better than another, but keep in minds these are “guidelines.” We don’t mind if you go for a different set of rules to these, just that you code keeps to a consistent set of them.

if (order.cooked) {
  // notice how this block if further right than the rest?

  availableWaiters.poll().serve(order);
  oven.offer(orderQueue.poll());
}

Spacing

It’s generally a good idea to space your code out a little. Putting spaces would make the code more readable by splitting it into easier to understand chunks.

Which one of these is easier to read?

let dx=Math.abs(x1-x2);
let dy=Math.abs(y1-x2);
let h=Math.sqrt(dx*dx,dy*dx);

let dx = Math.abs(x1 - x2);
let dy = Math.abs(y1 - x2);
let h = Math.sqrt(dx * dx, dy * dx);

Imagine how much more complex code may benefit from simpler digestible chunks.

Don’t Worry Too Much

You may have noticed Repl.it and other text coding editors like Atom and Visual Studio Code automatically push you in the way of writing properly formatted code, like indenting and formatting your code for you as you type.

If it gets too messy, you can right click on the code and select “Format Document.” This will format the code in whatever your editor’s preferred style is.

@

Not recently active