# Good coding practices

## Use Libs

BB have good [libs](/libs/what-it-is-libs.md). 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;

![](/files/lYk1igfoM4nj1mQcu2GF)

You can use folder in BJS too. For example in [before All](/bjs/always-running-commands.md#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!

![](/files/-MBM_KtAO04fro0IUVts)

## Use JSON property

**Bad code:**

![](/files/-MBM_RI9O_8FdcvO4BNI)

**Good code:**

![](/files/-MBM_Sxyn05xQgTLF5SO)

## Do not use many methods of getProperty or setProperty

**Bad code:**

![](/files/-MBMaOqLc_u7bQEpT-hm)

{% 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:**

![](/files/-MBMbI9-I7IR3CUSGQhR)

## Use functions!

Do not repeat youself!

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

![](/files/-MBM_crhAHxmI65if5iu)

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

![](/files/-MBM_YJoBmWUTjmcf4hV)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.bots.business/bjs/good-coding-practices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
