Betty Style

ยท

3 min read

Betty Style

What is Betty style and documentation in C programming?

As part of the Software Engineering program at ALX and Holberton School, we are taught to employ the Betty style of coding and Betty documentation when programming in C.

These are a set of guides crafted to ensure that the code we write is well written, documented, and presented in a way that anyone can easily understand.

Betty has therefore been developed as a code checker that checks whether a code written in the C language follows the Betty styles and documentation.

This checker throws in an error any time, it finds part of the written code violating either the styles or documentation guides.

Here is a summary of what the Betty checker checks for.

Betty Style of Coding Summary

To ensure that the checker does not flag your code with errors, pay attention to the following:

Multiple Statements or Assignments

In C programming, each statement is ended with a semi-colon ;. According to the Betty style of coding, no two statements should be put on the same line. Each statement should be on a single line.

Also, don't put multiple assignments on the same line.

Example of unacceptable code:

printf("I am checking for Betty style \n"); printf("Oops! Betty says I have some errors /n");

The above code will be flagged by the Betty checker. The correct version will be:

printf("I am checking for Betty style \n");

printf("Bravo! You passed my test. /n");

Indentation

One important thing that the betty checker looks for is how you indent your code. It is very critical about indentations, and for that matter, you will need to pay very close attention to it.

The rules for indentation in the Betty Style are:

  1. Never use spaces (don't click your spacebar key) for indentation.

  2. Use the tab key for indentation.

  3. Indent every block of code you write.

  4. You also have to indent the nested blocks of code.

Note: To be able to apply this style of indentation, you will need to understand what a block of code is in c programming

What is a block of code in C programming?

In C programming, a block is created with the curly brackets { }. Hence, anything within the curly bracket needs to be indented. An example is what we do with the main function.

int main(void)

{

printf("Here is your block of code \n");

printf("Can you see how I have been indented \n");

}

Any other thing will also be indented as such. But if you introduce a new block of code within this block of code then you would have to also indent that as well.

An example of a block of code that you can introduce include:

An if statement

A while loop

A do while loop

A for loop Any of these when introduced into your program will have their block of code indented as well. An example is:

{

printf("Here is your block of code \n");

printf("Can you see how I have been indented \n");

if (true)

{

printf("I passed Betty test \n");

}

}

You may also have one or more blocks of code nested in one another. Like an if statement within a while loop. You will need to further indent any additional block that you create.

The trick is, any time you type a new curly bracket {} in your code, the content of that curly bracket needs to be indented.

Betty linter

  • To run the Betty linter just with command betty <filename>:

  • Go to the Betty repository

  • Clone the repo to your local machine

  • cd into the Betty directory

  • Install the linter with sudo ./install.sh

  • emacs or vi a new file called betty.

ย