Writing clean code - A complete guide

I mean it’s still can be used for smaller scripts, or to show a preview of how a clean script should be for starter coders.

Other than that I never encountered an issue with this plugin, big scripts worked and looked nicer.

However, I guess you should type it out using your own method.

2 Likes

You missed an end over here for some reasons… I see this as an absolute error.

It is meant to be there to show the difference between messy and clean code with an error.

the error is meant to be there. It shoes that cleaner code is easier to find errors than messy code.

While your script is readable your functions aren’t versatile as they only work for leadertstats, This is a very important concept of functions, which in turn make your code more readable because now when you need to save items such as trails you don’t need to make a whole new Get() and Set() function.

here’s something I consider more versatile: first SetAsync should take in player, the data to save, and the datastore for eg:


https://gyazo.com/e254abcd4b8da308f5fe38c8b1b6768c

GetAsync should also take in the datastore:


https://gyazo.com/d96ad3f4477f644974ea397f629cf221

when GetAsync detects a new player return ‘NewPlayer’ and let the end user decide what to do:

https://gyazo.com/317027eff664775b9b068ec194aa3936

This makes your function’s versatile, sure it might take a little more setup since the function doesn’t automatically return leader stats data to you if the player is new, however the reusability it will offer in the long run will beat these 2 to 3 extra lines of code.

Rest of your points I agree with.

Your points are true, however it is not the point of the tutorial.

I thought it would fit into the tutorial though since it talks about clean code, and clean code usually comes from reusable code with other factors such as indenting, comments, ect.

Yes but, I am mainly talking about the format of your code rather then best practices when writing code. And I do agree that code should be versatile, just it is not the purpose for this tutorial.

Thanks my man, you really help newer developers with this!

1 Like