The biggest question is if it's worth it to use a useless if statement to make the x and y variables local away from the main statement.

    //Unconventional part, make it so that x and y are local variables
        int x,y;
        //set x and y to be the width + height of the terminal
        for(int i = 0; i < x; i++){
                //top border
                //bottom border
                mvaddch(y - 1,i,'#');
        for(int i = 0; i < y; i++){
                //left border
                //right border
                mvaddch(i,x - 1,'#');
  • 1
    \$\begingroup\$ You could just have a block; the if(true) could be left out \$\endgroup\$ – qxz Nov 26 '16 at 6:12
  • \$\begingroup\$ @qxz, he wants to make x and y local variables. He asks if it's worth it. I would say that he should just make it a function. \$\endgroup\$ – Incomputable Nov 26 '16 at 6:43
  • \$\begingroup\$ @Incomputable I was just making a comment that you can have a plain block without the if. I agree that I'd make it a function \$\endgroup\$ – qxz Nov 26 '16 at 6:44

You can create a block without an if statement. For example, these are equivalent:

    // some code

if (true) {
    // some code

But it's not a good practice to create blocks like this. It's a code smell, suggesting to wrap // some code in a dedicated function instead.

Anytime you think some neat trick is "unconventional", it's most probably a bad practice. Don't do it, fix it.


In addition to what @janos said:

Your formatting style looks weird. This is because in mvaddch(0,x - 1,'#') there is plenty of space around the - operator, but none around the ,. This commonly suggests that the , binds more tightly than the -, which is wrong.

So either use no space at all or use a space after the comma as well.


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.