22
\$\begingroup\$

I'm new to C programming and I recently challenged myself to writing a Tic-Tac-Toe program. I found that my code becomes lengthy very quickly with so many if statements. This code works as is (and I still wish to add more features). I just think there's probably a more neat/efficient way to program this. Any ideas on how to trim this?

#include <stdio.h>
#include <stdlib.h>

typedef int bool;
#define true 1
#define false 0

int main()
{
    playGame();
    return 0;
}
int playGame()
{

    char scanned[3];
    printf("Do you wish to play tick-tack-toe?\n");
    scanf("%s", scanned);
    if(strcasecmp(scanned,"yes")==0)
        startGame();

    else
    {
        if (strcmp(scanned,"no")==0 || strcmp(scanned,"nah")==0 || strcmp(scanned,"naw")==0)
        {
            printf("That's too bad!/nThis program will now end.");
            return 1;
        }
        printf("Not valid input!/nThis program will now end.");
        return 1;
    }
}
int startGame()
{
    //Sets up board for values 1-9;
    char board[3][3] =
    {
        {'1','2','3'},
        {'4','5','6'},
        {'7','8','9'}
    };

    bool winner = false;
    printf("\n\nHere is your playing board. Player One is Os and Player Two is Xs\n");
    printf("Entering a number 1-9 (then pushing enter) as shown below will use\nthe current Player's turn in that location.\n");


    printf("\n\n");
    printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);

    int x=0;
    int j=0;
    int turn[9];
    while (j<sizeof(turn)/sizeof(turn[0]) && winner == false)
    {
        scanf("%d",&turn[j]);
        //turn[j] = x;
        if (j%2==0)
        {
            if (turn[j]==1)
            {
                board[0][0] = 'O';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==2)
            {
                board[0][1] = 'O';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==3)
            {
                board[0][2] = 'O';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==4)
            {
                board[1][0] = 'O';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==5)
            {
                board[1][1] = 'O';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==6)
            {
                board[1][2] = 'O';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==7)
            {
                board[2][0] = 'O';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==8)
            {
                board[2][1] = 'O';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
        }
        if (turn[j]==9)
        {
            board[2][2] = 'O';
            printf("\n\n");
            printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
            printf("-----------\n");
            printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
            printf("-----------\n");
            printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
        }
        if (j%2!=0)
        {
            if (turn[j]==1)
            {
                board[0][0] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==2)
            {
                board[0][1] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==3)
            {
                board[0][2] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==4)
            {
                board[1][0] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==5)
            {
                board[1][1] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==6)
            {
                board[1][2] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==7)
            {
                board[2][0] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==8)
            {
                board[2][1] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }
            if (turn[j]==9)
            {
                board[2][2] = 'X';
                printf("\n\n");
                printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                printf("-----------\n");
                printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            }




        }


        j++;
    }
}
\$\endgroup\$
24
\$\begingroup\$

Boolean values

C99 has Boolean values: #include <stdbool.h>.

Variable names

int x=0;
int j=0;

x and j don't describe what they do. Is j the turn number? Also, I don't see x used anyway except this commented out line: //turn[j] = x;.

Repetition

I would set up a variable name to reduce all those ifs. Maybe something like:

char token = (j % 2 == 0) ? 'O' : 'X';

if (turn[j]==1)
{
    board[0][0] = token;
    printf("\n\n");
    printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
}

// ...

Also, nested for loops may be useful here to reduce that list of ifs to one value.

Edit:

In clarification to the comments, the ?: operator is a ternary conditional operator. It works as follows:

condition ? (run this statement if condition evaluated to true) : (run this statement if condition evaluated to false);

In this example, I used it in combination with an assignment operation.


C99 is informal terminology to mean ISO/IEC 9899:1999, which was finalized in 1999. The latest version of C is C11, which was finalized in 2011, and which should also support Boolean variables.

\$\endgroup\$
  • \$\begingroup\$ I was testing something earlier with an error I was getting, I'll remove x. \$\endgroup\$ – SuperGoA Jun 27 '15 at 2:52
21
\$\begingroup\$

From a quick glance, this snippet looks like it could be extracted into its own parameterized function:

    printf("\n\n");
    printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);

DRY - Don't Repeat Yourself ;-)

\$\endgroup\$
  • \$\begingroup\$ Oh and then I can just call the function over and over? \$\endgroup\$ – SuperGoA Jun 27 '15 at 2:51
  • 3
    \$\begingroup\$ Exactly that. Write once, use a bunch. \$\endgroup\$ – Hosch250 Jun 27 '15 at 2:55
  • 3
    \$\begingroup\$ this would be a good time to learn about huristics, the min/max algorithm, alpha/beta pruning and certain related topics. \$\endgroup\$ – user3629249 Jun 27 '15 at 3:23
14
\$\begingroup\$

Notes:

  • It seems that you don't need to store the input in the turn array
  • You are not asserting legal user input (values between 1 and 9)
  • You are not asserting that the user inputs a new value at every turn
  • Since user input is a single character, you may as well scan for "%c"
  • You can calculate the indexes to board based on the user input (turn)
  • You can calculate the player (x or o) based on the iteration number (j)
  • You are not changing the value of winner (initialized as false) anywhere

Implementation:

int  j;
char turn;
int  index;
char players[] = {'o','x'};

for (j=0; j<9; j++)
{
    while (1)
    {
        scanf("%c",&turn);
        if (turn == '\n')
            continue; // skip the newline character
        index = turn-'1';
        if (!(0 <= index && index <= 8))
            printf("Invalid input\n");
        else if (board[index/3][index%3] == players[0] ||
                 board[index/3][index%3] == players[1])
            printf("Already chosen\n");
        else
            break;
    }

    board[index/3][index%3] = players[j%2];

    printf("\n\n");
    printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);

    /*
    if there is a winner
    {
        print the winner
        break;
    }
    */
}

As you can see, I left it for you to check if there is a winner...

\$\endgroup\$
  • \$\begingroup\$ Thankyou, that makes sense. The code isn't fully complete yet, that is why some variables are unused :P \$\endgroup\$ – SuperGoA Jun 27 '15 at 3:45
10
\$\begingroup\$

Some big problems in your code others haven't mentioned:

  1. You use strcasecmp. This function is non-standard. This makes your code non-portable.
  2. You use

    scanf("%s", scanned);
    

    and scanf will happily scan unlimited characters and write it into scanned. You will (and already does) suffer from a buffer overflow. scanned can hold a maximum of 2 characters (+1 for the NUL-terminator). Typing more than two characters leads to Undefined Behavior as other characters are written into an invalid memory location.

    Fix this problem by changing

    char scanned[3];
    

    to

    char scanned[4]; /*Can hold a max of 3 chars (+1 for the NUL-terminator at the end)
    

    and

    scanf("%s", scanned);
    

    to

    scanf("%3s", scanned); /*Scan a max of 3 chars and append a NUL-terminator at the end*/
    

    Do note that you might have to clear the input buffer to remove extra characters (if the user inputs more than 3 characters).

  3. The function playGame() is designed to return an int. If the user types in "yes" for the scanf in playGame(), the if will execute and the function exits without a return statement. This leads to Undefined Behavior. Fix it by adding return 0; at the end of that function.
  4. The function startGame() is also designed to return an int, but you never return an int from it. This, again, leads to Undefined Behavior. If you do not want it to return a value change

    int startGame()
    

    to

    void startGame()
    

    which indicates that the function will not return any value.

Other issues:

  • You have a lot of repeating code:

    printf("\n\n");
    printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
    printf("-----------\n");
    printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
    

    which can be put into a function named printBoard():

    void printBoard() {
    
        printf("\n\n");
        printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
        printf("-----------\n");
        printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
        printf("-----------\n");
        printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
    }
    

    The logic used can also be simplified by using loops:

    void printBoard() {
    
        printf("\n\n");
    
        for(int i = 0; i < 3; i++) {
            printf(" %c | %c | %c\n", board[i][0], board[i][1], board[i][2]);
            printf("-----------\n");
        }
    }
    

    But this also prints the last printf an extra time, so use

    void printBoard() {
    
        printf("\n\n");
    
        for(int i = 0; i < 3; i++) {
            printf(" %c | %c | %c\n", board[i][0], board[i][1], board[i][2]);
            if(i != 2)
            {
                printf("-----------\n");
            }
        }
    }
    
  • Here:

    scanf("%d",&turn[j]);
    

    You don't check if user enters a valid number. You also store the inputs in an array. Why? So this:

    int turn[9];
    

    can be

    int turn;
    

    Checking the return value of scanf will reveal if the user enters a number or something else. If your scanf returns 1, it indicates that scanf successfully got a number as input and if it returns 0, it indicates that scanf failed to scan a number. It can also return -1(EOF) if it encounters a special value called EOF.

  • Use meaningful variable names instead of x,scanned etc. I leave this up to you.
  • This:

    else
    {
        if (strcmp(scanned,"no")==0 || strcmp(scanned,"nah")==0 || strcmp(scanned,"naw")==0)
        {
            printf("That's too bad!/nThis program will now end.");
            return 1;
        }
        printf("Not valid input!/nThis program will now end.");
        return 1;
    }
    

    can be written as

    else
    {
        char* exit_strings[] = {"no", "nah", "naw"};
    
        for(int i = 0; i < sizeof(exit_strings); i++)
            if (strcmp(scanned, exit_strings[i]) == 0)
            {
                printf("That's too bad!\n");
                printf("This program will now end.\n");
                return 1;
            }
        printf("Not valid input!\n");
        printf("This program will now end.\n");
        return 1;
    }
    

    making your code better. Note that you used /n while \n indicates a newline character.

\$\endgroup\$
  • \$\begingroup\$ You're implementation of printBoard with the for-loop is buggy. It should print a line of dashes between every other line. Right now it prints that line after each other line, which means one extra line is printed. \$\endgroup\$ – jacwah Jul 9 '15 at 8:45
  • \$\begingroup\$ @jacwah Yeah. Fixed it. \$\endgroup\$ – Spikatrix Jul 11 '15 at 6:38
7
\$\begingroup\$

Here is a revised working version of your code.

It includes the usage of boolean variables; deals with code-repetition; implements cases of wrong user inputs; and decides stalemate, winner cases.

#include <stdio.h>
#include <string.h>

void print(char board[][3])
{
    for (int i=0; i<3; i++)
    {
        printf(" %c | %c | %c\n", board[i][0], board[i][1], board[i][2]);
        if(i!=2)
            printf("-----------\n");
    }
}
bool winnerCheck(char board[][3], char check)
{
    bool winner = board[0][0]==check && board[0][1]==check && board[0][2]==check || board[1][0]==check && board[1][1]==check && board[1][2]==check || board[2][0]==check && board[2][1]==check && board[2][2]==check || board[0][0]==check && board[1][0]==check && board[2][0]==check || board[0][1]==check && board[1][1]==check && board[2][1]==check || board[0][2]==check && board[1][2]==check && board[2][2]==check || board[0][0]==check && board[1][1]==check && board[2][2]==check || board[0][2]==check && board[1][1]==check && board[2][0]==check;
    if (winner)
        printf("Player %d wins!\n", (check=='O')?1:2);
    return winner;
}
void startGame()
{
    //Sets up board for values 1-9;
    char board[3][3] =  {   {'1','2','3'},
                            {'4','5','6'},
                            {'7','8','9'}
                        };
    bool winner = false;
    printf("\nHere is your playing board. Player One is Os and Player Two is Xs\n");
    printf("Entering a number 1-9 (then pushing enter) as shown below will use\nthe current Player's turn in that location.\n\n");
    print(board);
    int j=0,cnt=9,turn;
    while (j<cnt && winner==false)
    {
        scanf("%d",&turn);
        if(board[turn/3][turn%3-1]!='O' && board[turn/3][turn%3-1]!='X')
            board[turn/3][turn%3-1] = (j%2==0)?'O':'X';
        else
        {
            printf("Illegal move\n");
            continue;
        }
        printf("\n\n");
        print(board);
        j++;
        winner = winnerCheck(board,'O') || winnerCheck(board,'X');
    }
    if(!winner)
        printf("Stalemate!\n");
}
int playGame()
{
    char scanned[10];
    printf("Do you wish to play tick-tack-toe?\n");
    scanf("%s", scanned);
    if(strcasecmp(scanned,"yes")==0)
        startGame();
    else
    {
        if (strcmp(scanned,"no")==0 || strcmp(scanned,"nah")==0 || strcmp(scanned,"naw")==0)
            printf("That's too bad!\nThis program will now end.");
        else
            printf("Not valid input!\nThis program will now end.");
        return 1;
    }
}
int main()
{
    playGame();
    return 0;
}

The changes are listed out:

  • One of the reasons to tackle the increasing length of your code was board printing repetition of code. This is handled by the usage of print(char board[][3]) function

  • Your code would not stop in case one of the winners has won; and at the end of the program, in case none of the users win, the program simply terminates. The winnerCheck(char board[][3], char check) takes in the board configuration and checks for the first/second user's winning condition. And after detecting a successful triumph, terminates after a notification to the players.

  • In case a user tries to make an illegal move at a location already occupied, the line of code : if(board[turn/3][turn%3-1]!='O' && board[turn/3][turn%3-1]!='X') takes care of this situation.

  • In case there is no winner, the program checks for the winner variable and notifies the players.

  • The else part of code in the playgame() function has repeated return 1; statements. The revised working code addresses the issue.

  • The turn array is not necessary and rather a character turn variable is used for taking in the user inputs. One may check the validity of the user's input as well since the number should be in [1-9] range. The board coordinates to be set can be decided using (turn/3,turn%3-1) rather than a set of if statements.

  • Something you may try: The user may enter a word longer than 3 characters; thus use a character array of longer than 3 length, say 10 charaters. But the user may use a 11 character word. Hence, as a solution, one may try to address this by specifying a boolean choice of [0/1] in the terminal and prompt the user to enter again if the choice is incorrect, since it may be possible that the user enters affirmative or negation words in different language or dialect.

\$\endgroup\$
  • \$\begingroup\$ Thank you, but as I said "I still wish to add features." I just wanted some ideas on how to minimize the lines code used given what I already had. \$\endgroup\$ – SuperGoA Jun 28 '15 at 23:16
  • 1
    \$\begingroup\$ @SuperGoA Yes, indeed. It is now 70 lines of code(good reduction from the previous 250 lines of code). \$\endgroup\$ – Vishal Anand Jun 28 '15 at 23:26
  • \$\begingroup\$ I think print is a really bad naming of a very specific function. It sound like a very general output function from the standard library. I'd call it something like printboard to remove ambiguity. \$\endgroup\$ – jacwah Jul 9 '15 at 8:55
  • \$\begingroup\$ @jacwah I agree. \$\endgroup\$ – Vishal Anand Apr 4 at 20:55
3
\$\begingroup\$

My answer is to use a "switch/case" expression. Here's how it works:

switch (expression that evaluates to int) {
    case 1:
    {
        // code to be executed if the expression evaluates to 1
        break;
    }
    // add as many cases as needed
    default:
    {
         // this is the "else" case.
         break;
    }
}

This way, you won't need to write statements such as these:

if (turn[j] == 1)
{
      // code
}

You can replace them with this:

switch(turn[j]) {
    case 1:
    {
        // code
        break;
    }
    case 2:
    {
        // more code
        break;
    }
    default
    {
        // it equals neither 1 nor 2
        break;
    }
}

In addition, instead of explicitly stating conditions for "if"s can only run if something is 0, you can simply remove the "==0" and put a binary "not" operator in front of the condition. (0 is binary for "false")

When you start the game, you can remove all of the "if" statements within what should be if (!(j%2)) and replace it with this:

board[(turn[j] - 1) / 3][(turn[j] - 1) % 3] = '0'
printf("\n\n %c | %c | %c\n-----------\n %c | %c | %c\n-----------\n %c | %c | %c\n", board[0][0], board[0][1], board[0][2], board[1][0], board[1][1], board[1][2], board[2][0], board[2][1], board[2][2]);
\$\endgroup\$
  • \$\begingroup\$ Why will the code better if OP puts lots of thing on one line, without breaking it off. I'd consider this bad practice, since you reduce readability a lot. \$\endgroup\$ – jacwah Jul 9 '15 at 8:57
  • \$\begingroup\$ @jacwah it reduces the number of lines and the size of the code by a couple bytes. \$\endgroup\$ – DDPWNAGE Jul 9 '15 at 18:04
  • \$\begingroup\$ Yes, but how is that beneficial? OP could omit all whitespace from they're code and reduce the size by ~0.5 KB, but the program would be incomprehensible. That's 0.00000005% of the capacity of my HDD. If space is a concern - use compression software like gzip. The easier code is to read, the easier it is to find bugs in it and to maintain it. This should be the aim of reviews. For writing as short code as possible there's Code Golf. \$\endgroup\$ – jacwah Jul 9 '15 at 18:29
  • \$\begingroup\$ @jacwah It also reduces a bit of work for the processor; it doesn't have to process a whole bunch of print(f) statements. \$\endgroup\$ – DDPWNAGE Jul 9 '15 at 18:30
  • \$\begingroup\$ That's potentially true, and the reason I also mentioned breaking the line off. \$\endgroup\$ – jacwah Jul 9 '15 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.