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

  • Home
  • SEARCH
  • 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 57937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:46:10+00:00 2026-05-10T17:46:10+00:00

Often, programmers write code that generates other code. (The technical term is metaprogramming ,

  • 0

Often, programmers write code that generates other code.

(The technical term is metaprogramming, but it is more common than merely cross-compilers; think about every PHP web-page that generates HTML or every XSLT file.)

One area I find challenging is coming up with techniques to ensure that both the hand-written source file, and the computer-generated object file are clearly indented to aid debugging. The two goals often seem to be competing.

I find this particularly challenging in the PHP/HTML combination. I think that is because:

  • there is sometimes more of the HTML code in the source file than the generating PHP
  • HTML files tend to be longer than, say, SQL statements, and need better indenting
  • HTML has space-sensitive features (e.g. between tags)
  • the result is more publicly visible HTML than SQL statements, so there is more pressure to do a reasonable job.

What techniques do you use to address this?


Edit: I accept that there are at least three arguments to not bothering to generate pretty HTML code:

  • Complexity of generating code is increased.
  • Makes no difference to rendering by browser; developers can use Firebug or similar to view it nicely.
  • Minor performance hit – increased download time for whitespace characters.

I have certainly sometimes generated code without thought to the indenting (especially SQL).

However, there are a few arguments pushing the other way:

  • I find, in practice, that I do frequently read generated code – having extra steps to access it is inconvenient.
  • HTML has some space-sensitivity issues that bite occasionally.

For example, consider the code:

<div class='foo'>     <?php         $fooHeader();         $fooBody();         $fooFooter();     ?> </div> 

It is clearer than the following code:

<div class='foo'><?php         $fooHeader();         $fooBody();         $fooFooter(); ?></div> 

However, it is also has different rendering because of the whitespace included in the HTML.

  • 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. 2026-05-10T17:46:10+00:00Added an answer on May 10, 2026 at 5:46 pm

    In the more general case, I have written XSLT code that generates C++ database interface code. Although at first I tried to output correctly indented code from the XSLT, this quickly became untenable. My solution was to completely ignore formatting in the XSLT output, and then run the resulting very long line of code through GNU indent. This produced a reasonably formatted C++ source file suitable for debugging.

    I can imagine the problem gets a lot more prickly when dealing with combined source such as HTML and PHP.

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

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Join mappings are a PITA! The problem here is that… May 11, 2026 at 10:45 pm
  • Editorial Team
    Editorial Team added an answer (From _row As DataGridViewRow In dgvChanges.Rows() your type of the… May 11, 2026 at 10:45 pm
  • Editorial Team
    Editorial Team added an answer Having code in the aspx file or in the code-behind… May 11, 2026 at 10:45 pm

Related Questions

I am asking this question because I know there are a lot of well-read
Sadly, I have a legacy PHP4 system that I continuously need to add features
When I am making methods with return values, I usually try and set things
Where I'm at we have a software package running on a mainframe system. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.