Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:49:53+00:00 2026-06-06T04:49:53+00:00

New to programming, I’ve held the (self imposed) notion that the less lines (of

  • 0

New to programming, I’ve held the (self imposed) notion that the less lines (of code), the better. Thus, when programming something, rather than having separate variables for pieces, I’ve been nesting all that I can into a line. For example:

preg_match('~><a href=~', substr(file_get_contents($match[1])), strpos($match[1], "help")), $match_rating)

Would it be more professional/generally-preferable to break the line above into separate variable chunks, so that it looks more like:

 preg_match($regExp, $bigString, $matches)

..With each variable/piece being defined above with its own line (and variable)?

I’ve wondered if this isn’t really better or more efficient, since it seems like it would make it difficult for someone else to read and decipher it. I realize it’s probably a personal preference type deal, but is there a generally held (professional) standard of which side to lean toward?


  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:49:54+00:00Added an answer on June 6, 2026 at 4:49 am

    Your first and foremost goal should be producing readable code that statest your intent clearly (using common idioms).

    Your second goal should be to ensure your program works as intended (keeping goal 1 in mind).

    If you fulfilled the first to goals and you find that there is a performance/memory problem, then you need to think how you can make the code more efficient. If you get to this part the first step is to measure where the problem is; then fix that one part (possibly deviating from goal 1 above) — rinse-and-repeat if there are still performance/memory issues.

    In your particular example it is often beneficial to store partial expressions in variables (e.g. you can inspect them readily in a debugger or print them out when debugging). If you have a decent compiler, this should not impact efficiency much (the compiler can optimize your code if needed).

    Also, it is preferable to keep lines short, so they are easy to read. Your first code sample should — at least — be broken into multiple lines (even if keeping the one expression)

    If you use variables for storing partial expression results, choose names that indicate the role of that variable — if there are multiple reg.ex’s you could be using, chose a name that indicates which one that is. This way you will help your readers understand your intent better

    Note: ordering of 1) and 2) is taste dependent, but if you go for “correctness” disregarding “readability”, you will find yourself having a hard-to-understand, thus hard-to-debug and hard-to-maintain code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say that you in your new programming work your boss comes and says
I always believed that when starting to learn a new programming language programmer must
New to programming. I wrote a Python code (with help from stackoverflow) to read
I'm a new iOS programming and I'm developing a simple iPhone game that needs
I'm new programming in shell and I need some help with this code... Buildname=
In designing a new programming language, is it safe to assume that a C
Hey, I'm a new programming enthusiast, just hobbling along on self-instruction. I just installed
Being new to programming I read a lot of sample code and try to
I'm new to programming in any sort of assembly, and since I've heard that
It seems that most new programming languages that have appeared in the last 20

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.