Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Etiquette of case statements

    Is there any reason NOT to put many lines of code into the cases in a switch statement? Many of the examples show switch statements with only a small handful of lines of code in each case. I realise this may gain a largely opinion based response but I'd be interested to hear it nonetheless.

    I'm a reasonably experienced PHP programmer but have only worked in small groups or on solo projects and wonder if I have developed a habit of avoiding long code fragments within switch statements that isn't necessarily useful.

  2. #2
    Regular Coder Vege's Avatar
    Join Date
    Jan 2008
    Posts
    982
    Thanks
    22
    Thanked 132 Times in 131 Posts
    It's more about scope length. In general function/method over 30ish lines is too long.

  3. #3
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,736
    Thanks
    26
    Thanked 590 Times in 583 Posts
    Quote Originally Posted by Vege View Post
    In general function/method over 30ish lines is too long.
    The code gets hard to read if you exceed that limit.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •