# Good coding practices

## Use Libs

BB have good [libs](https://help.bots.business/libs). Just install needed library to your bot.

{% hint style="warning" %}
Don't install unnecessary libraries. Your bot might be slow after that.
{% endhint %}

## Use folders

You can organize your commands in folders.&#x20;

![](https://3310729168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LVh0yg9olT-QWqi3AYt%2Fuploads%2F9u8W4X7uJ6qrGx5seCpI%2Fimage.png?alt=media\&token=974830b5-616d-4c13-b154-e43e24ba9e30)

You can use folder in BJS too. For example in [before All](https://help.bots.business/always-running-commands#beforeall-and-afterall-commands) command:

```javascript
// Before all command - @

// set your ADMIN_ID here
// you can get it via Bot.sendMessage(user.id)
var isAdmin = ( user && (user.id == ADMIN_ID) )

if(!command){
   return
}

if((command.folder=="Admin Panel")&&(isAdmin){
  // only admin can run command from Admin Panel's folder
  // any common bjs here for admin
  Bot.sendMessage("Hello, admin!")
}else{
  Bot.sendMessage("Access denied");
  return // exit from command now
}

// other example
if(command.folder=="Under development"){
  Bot.sendMessage("Sorry this command on development")
}
```

## Use good names

Do you have children.

Two boys and one girl. You do not call them b1, b2 ang g1, are you not ?

So why do you call your variables like that?

**Bad examples:**

* x1
* y2
* d3

**Good:**

* currentLimit
* maxCount
* userName

## Use simular names!

![](https://3310729168-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVh0yg9olT-QWqi3AYt%2F-MBMZUPKxhRy_qxSisXK%2F-MBM_KtAO04fro0IUVts%2Fimage.png?alt=media\&token=87f75eed-53a3-4941-9a8f-e3c042148c29)

## Use JSON property

**Bad code:**

![](https://3310729168-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVh0yg9olT-QWqi3AYt%2F-MBMZUPKxhRy_qxSisXK%2F-MBM_RI9O_8FdcvO4BNI%2Fimage.png?alt=media\&token=315dcc9f-837b-47d3-be37-edb41f3957dc)

**Good code:**

![](https://3310729168-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVh0yg9olT-QWqi3AYt%2F-MBMZUPKxhRy_qxSisXK%2F-MBM_Sxyn05xQgTLF5SO%2Fimage.png?alt=media\&token=258bbbea-061e-417e-9d38-12107c81598f)

## Do not use many methods of getProperty or setProperty

**Bad code:**

![](https://3310729168-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVh0yg9olT-QWqi3AYt%2F-MBMZUPKxhRy_qxSisXK%2F-MBMaOqLc_u7bQEpT-hm%2Fimage.png?alt=media\&token=5fe5d71e-2b15-41da-8548-d800997ae83a)

{% hint style="warning" %}
Each getProperty method spent above 10-100 ms for execution. So if you have 10 getProperty methods bot can spent above 1 sec for execution! It is slowly
{% endhint %}

**Use JSON type:**

![](https://3310729168-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVh0yg9olT-QWqi3AYt%2F-MBMZUPKxhRy_qxSisXK%2F-MBMbI9-I7IR3CUSGQhR%2Fimage.png?alt=media\&token=229f6cc7-6fe9-4a2c-807d-eb02883a8eb6)

## Use functions!

Do not repeat youself!

Bad code:![](https://telegra.ph/file/31bc228cf1f6f793ff034.png)

![](https://3310729168-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVh0yg9olT-QWqi3AYt%2F-MBMZUPKxhRy_qxSisXK%2F-MBM_crhAHxmI65if5iu%2Fimage.png?alt=media\&token=6ded5119-e97c-4b42-b7e0-85be217a1fcc)

Good code:![](https://telegra.ph/file/aa3021f92fbd73e5c9ede.png)

![](https://3310729168-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LVh0yg9olT-QWqi3AYt%2F-MBMZUPKxhRy_qxSisXK%2F-MBM_YJoBmWUTjmcf4hV%2Fimage.png?alt=media\&token=9d92d674-809f-4aeb-b205-1c400789edc0)
