micheal-kyagulanyi / allether-pizza-api

Simple pizza order API
0 stars 1 forks source link

language/library features/shortcuts/syntax #3

Open 0xF48 opened 4 years ago

0xF48 commented 4 years ago

this is a very minor issue, but something to watch out for in the future.

var obj = new Object() is the same as var obj = {}, it's not a good idea (in my opinion) to write new Object because it complicates the readability of the code on my end. you are doing Sauce.find({}) which the same as Sauce.find(new Object()) which is the same as Sauce.find()

it's okay to do it the way you are doing it currently but keep in mind when refactoring code in the future, if there is a shorter/faster/easier way of doing things, do it that way instead and don't reinvent the wheel or write extra abstractions that add extra unnecessary code that others will need to read.

the idea is to keep the code as simple and easy as possible for others and your future self to understand by using all the right tools & features of the language and it's libraries as possible, which will naturally come with time and practice.

0xF48 commented 4 years ago
require('./../model/meat');

can be

require('../model/meat');
0xF48 commented 4 years ago
orderPizzas = new Array()

can be

orderPizzas = []
0xF48 commented 4 years ago

camelCase notation for variables is fine, different people do it different ways, as long as you have a a strict and systematic way of doing it.

something to watch out for in the future is the fact that if I use underscore_names for variables in most of the allether source code and camelCase for functions and methods and UpperCase for class names. You don't have to do this if you don't want to however, perfectly fine with me, i don't care either way. In fact, I like the camelCase better because it's easier to type its just a habit that i have formed over a period of time.

0xF48 commented 4 years ago

Commenting code is fine, you can do so for yourself if you need to. Personally, I don't care if you do it or not.

However i do care very much about clean and organized code and variable names that make sense.

All of your variable names are very good and clear to understand, I appreciate that a lot! 👏

0xF48 commented 4 years ago

again, a lot of this stuff is minor and will come naturally with time as you familiarize yourself with the language/tools more.

0xF48 commented 4 years ago

I also like how you use reduce

const meatCal = toSaveMeats.reduce(
                        (currentCal, meat) => {
                            return meat.calCount + currentCal;
                        }, 
                        0
                    );

it's always nice to see handy utility functions used in a good way!

0xF48 commented 4 years ago

I also appreciate your proper use of array methods like

var amountsDetail = dbDrink.sizes.find((amount) => {
  return amount.name === orderDrink.size;
});

I use lodash for a lot of this kind of stuff, you can take a look at it if you wish, it contains many useful toolbelt utility functions.

It's always best to use the right tools for the job and avoiding using any sort of for loops is always great practice.