decoder__'s blog

By decoder__, history, 7 weeks ago, In English

I have seen in many people's code that they use a solve function instead of writing the logic in the main function. What advantage it has over writing the code directly in the main function?

 
 
 
 
  • Vote: I like it
  • +7
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it +72 Vote: I do not like it

You can use return directly in solve() in case there are test cases, while in int main() you can't

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it -28 Vote: I do not like it

    "continue" keyword is also there.

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it +13 Vote: I do not like it

      but you have to use many breaks statements too if you want to end the current test case from a loop

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        i just use goto statement to go back to the starting of the test case loop, is that less efficient?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Actually you can use goto but that would make spaghetti code

»
7 weeks ago, # |
  Vote: I like it +17 Vote: I do not like it

I personally use it because you can easily end the function with return(end).

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

The no. of if else statements increases if you don't use it...

»
7 weeks ago, # |
  Vote: I like it -26 Vote: I do not like it

I think it doesnt have obvious advantages. But many people are used to it since it looks comfortable. After all, the choice is up to you.

»
7 weeks ago, # |
  Vote: I like it +12 Vote: I do not like it

It's good to split everything in functions

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thanks, sensei for the information :)

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it +24 Vote: I do not like it

    hey, wait where did the girl go ?? so you were dude all along (confused screaming).

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it +23 Vote: I do not like it

      She probably changed her name as a joke. Danil is a famous Youtuber, well known for his staring contest videos (Google him if you don’t believe me). Definitely not her.

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it -10 Vote: I do not like it

        thanks for the information but now you are just spoiling my joke.

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I have seen the comments and knew that she was a singer. thanks for the name :) , hey are not doing YouTube thing anymore.

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I've googled but found nothing, can you provide the link?

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Isn't it too obvious? Asking everything sucks

»
7 weeks ago, # |
  Vote: I like it +5 Vote: I do not like it

What is there in it to downvote except colortag?

»
7 weeks ago, # |
  Vote: I like it +20 Vote: I do not like it
solve()
main()

You decide.

»
6 weeks ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

.....................................................................................