473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Mangled Code Mess

I have inherited a php script that nests php, javascript, and html.
How do I clean up code like this:
I think I can move the javascript into a seperate .js file at the
least. What about the nesting of php inside the html?

<?php

....snip...

function ShowCart()
{
...
?>
<html>
...
<script language="JavaScript">
function UpdateQty(item, backPage)
{
...
}
</script>
</head>
<body bgcolor="#ffffff">
...
<?php
while($row = @mysql_fetch_array($result))
{
...
?>
<tr>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
<select name="<?php echo $row["itemId"]; ?>"
onChange="UpdateQty(this,'<?php echo $_GET['back']; ?>')">
....
}

Dec 11 '06 #1
24 1493
If you print the HTML from the function instead of switching languages,
legibility will improve significantly and you have more control what
HTML is generated.

Best regards

Skijor wrote:
I have inherited a php script that nests php, javascript, and html.
How do I clean up code like this:
I think I can move the javascript into a seperate .js file at the
least. What about the nesting of php inside the html?

<?php

...snip...

function ShowCart()
{
...
?>
<html>
...
<script language="JavaScript">
function UpdateQty(item, backPage)
{
...
}
</script>
</head>
<body bgcolor="#ffffff">
...
<?php
while($row = @mysql_fetch_array($result))
{
...
?>
<tr>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
<select name="<?php echo $row["itemId"]; ?>"
onChange="UpdateQty(this,'<?php echo $_GET['back']; ?>')">
....
}
Dec 11 '06 #2
Skijor wrote:
I have inherited a php script that nests php, javascript, and html.
How do I clean up code like this:
I think I can move the javascript into a seperate .js file at the
least. What about the nesting of php inside the html?

<?php

...snip...

function ShowCart()
{
...
?>
<html>
...
<script language="JavaScript">
function UpdateQty(item, backPage)
{
...
}
</script>
</head>
<body bgcolor="#ffffff">
...
<?php
while($row = @mysql_fetch_array($result))
{
...
?>
<tr>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
<select name="<?php echo $row["itemId"]; ?>"
onChange="UpdateQty(this,'<?php echo $_GET['back']; ?>')">
....
}
I guess I don't see switching back and forth between html and php as so
much of a problem. Most WYSIWYG editors won't display html code from an
echo or print statement, while they will plain html.

Although I do think this is a little strange - I normally don't have a
single function which does the headers, etc. Rather, most of my page is
HTML, with a PHP inserted as required. The code you inherited seems to
be mostly PHP with a little html thrown in.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 11 '06 #3
This is old-style dirty PHP programming. There are a lot of stupid programmers
who mingle/mangle code like this trying to be cute. Instead of some HTML
with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP should
be the control, HTML should not be.

<?php

$var = 1 + 1 ;

print <<<ENDOFHTML
<html>
<table>
<tr>
<td>
$var
</td>
</tr>
</table>

ENDOFHTML;

$some_more_php = 2 + 2 ;

print <<<ENDOFHTML
$some_more_php
ENDOFHMTL;

?>

A lot of web servers won't be set up for HTML-with-PHP but if you have
a web server with PHP enabled, you can always throw in HTML. Programmers
who mix PHP into HTML just don't know how to program cleanly.

-DE-

Skijor wrote:
I have inherited a php script that nests php, javascript, and html.
How do I clean up code like this:
I think I can move the javascript into a seperate .js file at the
least. What about the nesting of php inside the html?

<?php

...snip...

function ShowCart()
{
...
?>
<html>
...
<script language="JavaScript">
function UpdateQty(item, backPage)
{
...
}
</script>
</head>
<body bgcolor="#ffffff">
...
<?php
while($row = @mysql_fetch_array($result))
{
...
?>
<tr>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
<select name="<?php echo $row["itemId"]; ?>"
onChange="UpdateQty(this,'<?php echo $_GET['back']; ?>')">
....
}
Dec 11 '06 #4
see end of post:

Double Echo wrote:
This is old-style dirty PHP programming. There are a lot of stupid
programmers
who mingle/mangle code like this trying to be cute. Instead of some HTML
with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP
should be the control, HTML should not be.

<?php

$var = 1 + 1 ;

print <<<ENDOFHTML
<html>
<table>
<tr>
<td>
$var
</td>
</tr>
</table>

ENDOFHTML;

$some_more_php = 2 + 2 ;

print <<<ENDOFHTML
$some_more_php
ENDOFHMTL;

?>

A lot of web servers won't be set up for HTML-with-PHP but if you have
a web server with PHP enabled, you can always throw in HTML. Programmers
who mix PHP into HTML just don't know how to program cleanly.

-DE-
DE.
for a newbie, who likes your style, please reference or explain
the syntax:

print <<<ENDOFHTML

bill
Dec 11 '06 #5
Here's the PHP manual's page on heredoc syntax:

http://php.net/manual/en/language.ty...syntax.heredoc

On Dec 11, 7:19 am, bill <nob...@spamcop.netwrote:
see end of post:

Double Echo wrote:
This is old-style dirty PHP programming. There are a lot of stupid
programmers
who mingle/mangle code like this trying to be cute. Instead of some HTML
with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP
should be the control, HTML should not be.
<?php
$var = 1 + 1 ;
print <<<ENDOFHTML
<html>
<table>
<tr>
<td>
$var
</td>
</tr>
</table>
ENDOFHTML;
$some_more_php = 2 + 2 ;
print <<<ENDOFHTML
$some_more_php
ENDOFHMTL;
?>
A lot of web servers won't be set up for HTML-with-PHP but if you have
a web server with PHP enabled, you can always throw in HTML. Programmers
who mix PHP into HTML just don't know how to program cleanly.
-DE-DE.
for a newbie, who likes your style, please reference or explain
the syntax:

print <<<ENDOFHTML

bill
Dec 12 '06 #6
Curtis wrote:
Here's the PHP manual's page on heredoc syntax:

http://php.net/manual/en/language.ty...syntax.heredoc
many thanks, that is great.

bill
>
On Dec 11, 7:19 am, bill <nob...@spamcop.netwrote:
>see end of post:

Double Echo wrote:
>>This is old-style dirty PHP programming. There are a lot of stupid
programmers
who mingle/mangle code like this trying to be cute. Instead of some HTML
with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP
should be the control, HTML should not be.
<?php
$var = 1 + 1 ;
print <<<ENDOFHTML
<html>
<table>
<tr>
<td>
$var
</td>
</tr>
</table>
ENDOFHTML;
$some_more_php = 2 + 2 ;
print <<<ENDOFHTML
$some_more_php
ENDOFHMTL;
?>
A lot of web servers won't be set up for HTML-with-PHP but if you have
a web server with PHP enabled, you can always throw in HTML. Programmers
who mix PHP into HTML just don't know how to program cleanly.
-DE-DE.
for a newbie, who likes your style, please reference or explain
the syntax:

print <<<ENDOFHTML

bill
Dec 12 '06 #7
Curtis wrote:
Here's the PHP manual's page on heredoc syntax:

http://php.net/manual/en/language.ty...syntax.heredoc

On Dec 11, 7:19 am, bill <nob...@spamcop.netwrote:
>see end of post:

Double Echo wrote:
>>This is old-style dirty PHP programming. There are a lot of stupid
programmers
who mingle/mangle code like this trying to be cute. Instead of some HTML
with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP
should be the control, HTML should not be.
<?php
$var = 1 + 1 ;
print <<<ENDOFHTML
<html>
<table>
<tr>
<td>
$var
</td>
</tr>
</table>
ENDOFHTML;
$some_more_php = 2 + 2 ;
print <<<ENDOFHTML
$some_more_php
ENDOFHMTL;
?>
A lot of web servers won't be set up for HTML-with-PHP but if you have
a web server with PHP enabled, you can always throw in HTML. Programmers
who mix PHP into HTML just don't know how to program cleanly.
-DE-DE.
for a newbie, who likes your style, please reference or explain
the syntax:

print <<<ENDOFHTML

bill
That sure will make writing html with embedded PHP variables a
LOT more straightforward !

bill
Dec 12 '06 #8
Thanks all.

As far as the JavaScript definitions go, is there really a good reason
to generate the functions on the fly like this? I assume I can just
statically define them in a .js file instead of creating them on the
fly every time my php code is called. The assumption being I replace
the function definitions with function calls in the php-generated HTML.
bill wrote:
Curtis wrote:
Here's the PHP manual's page on heredoc syntax:

http://php.net/manual/en/language.ty...syntax.heredoc

On Dec 11, 7:19 am, bill <nob...@spamcop.netwrote:
see end of post:

Double Echo wrote:
This is old-style dirty PHP programming. There are a lot of stupid
programmers
who mingle/mangle code like this trying to be cute. Instead of some HTML
with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP
should be the control, HTML should not be.
<?php
$var = 1 + 1 ;
print <<<ENDOFHTML
<html>
<table>
<tr>
<td>
$var
</td>
</tr>
</table>
ENDOFHTML;
$some_more_php = 2 + 2 ;
print <<<ENDOFHTML
$some_more_php
ENDOFHMTL;
?>
A lot of web servers won't be set up for HTML-with-PHP but if you have
a web server with PHP enabled, you can always throw in HTML. Programmers
who mix PHP into HTML just don't know how to program cleanly.
-DE-DE.
for a newbie, who likes your style, please reference or explain
the syntax:

print <<<ENDOFHTML

bill

That sure will make writing html with embedded PHP variables a
LOT more straightforward !

bill
Dec 14 '06 #9
As long as the JavaScript isn't relying on data passed by PHP, you
should be fine by storing the JS in its own file, which is usually the
case. Usually, it's best to keep the presentation tier separate from
the business logic anyway.

Curtis

Skijor wrote:
Thanks all.

As far as the JavaScript definitions go, is there really a good reason
to generate the functions on the fly like this? I assume I can just
statically define them in a .js file instead of creating them on the
fly every time my php code is called. The assumption being I replace
the function definitions with function calls in the php-generated HTML.
bill wrote:
Curtis wrote:
Here's the PHP manual's page on heredoc syntax:
>
http://php.net/manual/en/language.ty...syntax.heredoc
>
On Dec 11, 7:19 am, bill <nob...@spamcop.netwrote:
>see end of post:
>>
>>
>>
>Double Echo wrote:
>>This is old-style dirty PHP programming. There are a lot of stupid
>>programmers
>>who mingle/mangle code like this trying to be cute. Instead of some HTML
>>with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP
>>should be the control, HTML should not be.
>><?php
>>$var = 1 + 1 ;
>>print <<<ENDOFHTML
>><html>
>><table>
>><tr>
>><td>
>>$var
>></td>
>></tr>
>></table>
>>ENDOFHTML;
>>$some_more_php = 2 + 2 ;
>>print <<<ENDOFHTML
>>$some_more_php
>>ENDOFHMTL;
>>?>
>>A lot of web servers won't be set up for HTML-with-PHP but if you have
>>a web server with PHP enabled, you can always throw in HTML. Programmers
>>who mix PHP into HTML just don't know how to program cleanly.
>>-DE-DE.
>for a newbie, who likes your style, please reference or explain
>the syntax:
>>
>print <<<ENDOFHTML
>>
>bill
>
That sure will make writing html with embedded PHP variables a
LOT more straightforward !

bill
Dec 14 '06 #10
Bill,

Sorry for not getting back sooner... had a lot of work interrupting my newsgroup time. :-)

Here-doc allows you to basically print out whatever is between the pattern you choose.

I use ENDOFHTML but you could use ENDOFCODE or whatever.

Perl has a similar construct:

print <<ENDOFHTML;
ENDOFHTML

Notice the semi-colon at the top, PHP is a bit more "correct" putting the semi-colon at
the end:

print <<<ENDOFHTML
ENDOFHTML;

PHP also uses "<<<" whereas Perl uses "<<".

Anyway, embedded PHP programs were the rave a couple of years ago, and people were doing
it trying to create really dynamic pages, but it's really messy as you've found out to
do it that way.

It's easier to print <<<EDNDOFHTML because you can actually use ' and "
in the block without trouble. There are also a lot of web servers that don't like embedded
PHP in HTML docs and will barf or ignore it if you attempt it. So, it's better to embed HTML in PHP,
and save yourself the hassle. One note, be careful about the placement at the end, the
end tag _must_ be over at the left, and no space after it, or it won't work.

bill wrote:
see end of post:

Double Echo wrote:
>This is old-style dirty PHP programming. There are a lot of stupid
programmers
who mingle/mangle code like this trying to be cute. Instead of some HTML
with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP
should be the control, HTML should not be.

<?php

$var = 1 + 1 ;

print <<<ENDOFHTML
<html>
<table>
<tr>
<td>
$var
</td>
</tr>
</table>

ENDOFHTML;

$some_more_php = 2 + 2 ;

print <<<ENDOFHTML
$some_more_php
ENDOFHMTL;

?>

A lot of web servers won't be set up for HTML-with-PHP but if you have
a web server with PHP enabled, you can always throw in HTML. Programmers
who mix PHP into HTML just don't know how to program cleanly.

-DE-
DE.
for a newbie, who likes your style, please reference or explain the syntax:

print <<<ENDOFHTML

bill
Dec 14 '06 #11
In article <bI*****************@fe56.usenetserver.com>,
Double Echo <do********@your.comwrote:
Bill,

Sorry for not getting back sooner... had a lot of work interrupting my
newsgroup time. :-)

Here-doc allows you to basically print out whatever is between the pattern
you choose.

I use ENDOFHTML but you could use ENDOFCODE or whatever.

Perl has a similar construct:

print <<ENDOFHTML;
ENDOFHTML

Notice the semi-colon at the top, PHP is a bit more "correct" putting the
semi-colon at
the end:

print <<<ENDOFHTML
ENDOFHTML;

PHP also uses "<<<" whereas Perl uses "<<".

Anyway, embedded PHP programs were the rave a couple of years ago, and people
were doing
it trying to create really dynamic pages, but it's really messy as you've
found out to
do it that way.

It's easier to print <<<EDNDOFHTML because you can actually use ' and "
in the block without trouble. There are also a lot of web servers that don't
like embedded
PHP in HTML docs and will barf or ignore it if you attempt it. So, it's
better to embed HTML in PHP,
and save yourself the hassle.
No, I've gone away from this approach and had no problems at all. My
pages embed the PHP in the HTML. Its a lot easier that way. I use PHP to
dynamically generate the html based on what is in our mysql database.

-- tim
Dec 14 '06 #12
Tim Streater wrote:
In article <bI*****************@fe56.usenetserver.com>,
Double Echo <do********@your.comwrote:
>Bill,

Sorry for not getting back sooner... had a lot of work interrupting my
newsgroup time. :-)

Here-doc allows you to basically print out whatever is between the pattern
you choose.

I use ENDOFHTML but you could use ENDOFCODE or whatever.

Perl has a similar construct:

print <<ENDOFHTML;
ENDOFHTML

Notice the semi-colon at the top, PHP is a bit more "correct" putting the
semi-colon at
the end:

print <<<ENDOFHTML
ENDOFHTML;

PHP also uses "<<<" whereas Perl uses "<<".

Anyway, embedded PHP programs were the rave a couple of years ago, and people
were doing
it trying to create really dynamic pages, but it's really messy as you've
found out to
do it that way.

It's easier to print <<<EDNDOFHTML because you can actually use ' and "
in the block without trouble. There are also a lot of web servers that don't
like embedded
PHP in HTML docs and will barf or ignore it if you attempt it. So, it's
better to embed HTML in PHP,
and save yourself the hassle.

No, I've gone away from this approach and had no problems at all. My
pages embed the PHP in the HTML. Its a lot easier that way. I use PHP to
dynamically generate the html based on what is in our mysql database.

-- tim

It might be easier for _you_, but not for the next poor bastard that will have
to agonize at the shitmess you made.

There is no excuse for shitty-looking code. Another annoyance for me are people
who have to roll-up their brackets as if there is a line penalty for good, structured
code. Like you're going to run out of lines or air or something.

People who like to

if (...) {
}

or

while(...) {
}

annoy the fuck-out-of-me because I have to stop, read really slowly and try to grasp
the nesting, and logic. It's all rolled up so you can't hardly separate the code into
something readable.

It's so much cleaner to

if ( ... )
{
code here
}

or

while( ... )
{
code here
}

but all the goddam schools preach shitmess roll-up coding and OO. It works but it's so fucking
messy. You fucking kids think it's cool code, and wow, neato, but then somebody else has to
work on it, and it's a fucking nightmare. Clean code, nested, and properly written will allow
the code to be debugged better, and probably survive being re-written all over again because you
can actually read it. I've gone on to delete code I can't read and just re-wrote it cleanly.

-DE- ( using my best Dr. House imitation )
Dec 14 '06 #13
Tim Streater wrote:
In article <bI*****************@fe56.usenetserver.com>,
Double Echo <do********@your.comwrote:

>>Bill,

Sorry for not getting back sooner... had a lot of work interrupting my
newsgroup time. :-)

Here-doc allows you to basically print out whatever is between the pattern
you choose.

I use ENDOFHTML but you could use ENDOFCODE or whatever.

Perl has a similar construct:

print <<ENDOFHTML;
ENDOFHTML

Notice the semi-colon at the top, PHP is a bit more "correct" putting the
semi-colon at
the end:

print <<<ENDOFHTML
ENDOFHTML;

PHP also uses "<<<" whereas Perl uses "<<".

Anyway, embedded PHP programs were the rave a couple of years ago, and people
were doing
it trying to create really dynamic pages, but it's really messy as you've
found out to
do it that way.

It's easier to print <<<EDNDOFHTML because you can actually use ' and "
in the block without trouble. There are also a lot of web servers that don't
like embedded
PHP in HTML docs and will barf or ignore it if you attempt it. So, it's
better to embed HTML in PHP,
and save yourself the hassle.


No, I've gone away from this approach and had no problems at all. My
pages embed the PHP in the HTML. Its a lot easier that way. I use PHP to
dynamically generate the html based on what is in our mysql database.

-- tim
Hi, Tim,

I agree with you. And I find this style, even when written by someone
else, to be much easier to follow than echoing everything from PHP.

But it's a matter of programming style. Some like it, some don't.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 14 '06 #14
Double Echo wrote:
Tim Streater wrote:
>In article <bI*****************@fe56.usenetserver.com>,
Double Echo <do********@your.comwrote:
>>Bill,

Sorry for not getting back sooner... had a lot of work interrupting
my newsgroup time. :-)

Here-doc allows you to basically print out whatever is between the
pattern you choose.

I use ENDOFHTML but you could use ENDOFCODE or whatever.

Perl has a similar construct:

print <<ENDOFHTML;
ENDOFHTML

Notice the semi-colon at the top, PHP is a bit more "correct" putting
the semi-colon at
the end:

print <<<ENDOFHTML
ENDOFHTML;

PHP also uses "<<<" whereas Perl uses "<<".

Anyway, embedded PHP programs were the rave a couple of years ago,
and people were doing
it trying to create really dynamic pages, but it's really messy as
you've found out to do it that way.
It's easier to print <<<EDNDOFHTML because you can actually use ' and "
in the block without trouble. There are also a lot of web servers
that don't like embedded
PHP in HTML docs and will barf or ignore it if you attempt it. So,
it's better to embed HTML in PHP,
and save yourself the hassle.


No, I've gone away from this approach and had no problems at all. My
pages embed the PHP in the HTML. Its a lot easier that way. I use PHP
to dynamically generate the html based on what is in our mysql database.

-- tim

It might be easier for _you_, but not for the next poor bastard that
will have
to agonize at the shitmess you made.
I disagree. I like this style also, and find this style to be much
easier to troubleshoot and modify than echoing everything from PHP.
There is no excuse for shitty-looking code. Another annoyance for me
are people
who have to roll-up their brackets as if there is a line penalty for
good, structured
code. Like you're going to run out of lines or air or something.
Agreed. And personally, I think your style looks pretty shitty. But
it's only my opinion, and it's a matter of what you're used to.
People who like to
if (...) {
}

or

while(...) {
}

annoy the fuck-out-of-me because I have to stop, read really slowly and
try to grasp
the nesting, and logic. It's all rolled up so you can't hardly separate
the code into
something readable.
And I find hundreds of unnecessary echo statements to be unnecessarily
ugly and complicating.
It's so much cleaner to

if ( ... )
{
code here
}

or
while( ... )
{
code here
}
Sure. But when you add dozens of echo statements in your braces, it
gets a lot more complicated. And when you start concatenating strings
together to get variables and html... terrible!
but all the goddam schools preach shitmess roll-up coding and OO. It
works but it's so fucking
messy. You fucking kids think it's cool code, and wow, neato, but then
somebody else has to
work on it, and it's a fucking nightmare. Clean code, nested, and
properly written will allow
the code to be debugged better, and probably survive being re-written
all over again because you
can actually read it. I've gone on to delete code I can't read and just
re-wrote it cleanly.

-DE- ( using my best Dr. House imitation )

Well, if "all the goddam schools" teach it, there must be something to
it, don't you think?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 14 '06 #15
In article <mh******************@fe09.usenetserver.com>,
Double Echo <do********@your.comwrote:
It might be easier for _you_, but not for the next poor bastard that will
have to agonize at the shitmess you made.
My code is carefully laid out, thank you.
There is no excuse for shitty-looking code. Another annoyance for me are
people
who have to roll-up their brackets as if there is a line penalty for good,
structured
code. Like you're going to run out of lines or air or something.

People who like to

if (...) {
}

or

while(...) {
}

annoy the fuck-out-of-me because I have to stop, read really slowly and try
to grasp
the nesting, and logic. It's all rolled up so you can't hardly separate the
code into
something readable.

It's so much cleaner to

if ( ... )
{
code here
}

or

while( ... )
{
code here
}
Funnily enough I completely agree here. If the braces are lined up then
matching braces are so much easier to find.
but all the goddam schools preach shitmess roll-up coding and OO. It works
but it's so fucking
messy. You fucking kids think it's cool code, and wow, neato, but then
somebody else has to
work on it, and it's a fucking nightmare. Clean code, nested, and properly
written will allow
the code to be debugged better, and probably survive being re-written all
over again because you
can actually read it. I've gone on to delete code I can't read and just
re-wrote it cleanly.
When what you are dealing with is spaghetti this may well be necessary.

-- tim
Dec 15 '06 #16
In article <fb******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:
Double Echo wrote:
[...]
>
but all the goddam schools preach shitmess roll-up coding and OO. It
works but it's so fucking
messy. You fucking kids think it's cool code, and wow, neato, but then
somebody else has to
work on it, and it's a fucking nightmare. Clean code, nested, and
properly written will allow
the code to be debugged better, and probably survive being re-written
all over again because you
can actually read it. I've gone on to delete code I can't read and just
re-wrote it cleanly.

-DE- ( using my best Dr. House imitation )

Well, if "all the goddam schools" teach it, there must be something to
it, don't you think?
It's just the vogue at the moment. Those of us who have developed a
coding style over 40 years to assist maintainers who might be following,
think different. Cool is not important - maintainability is (and
donkeymentation, of course).

Personally I dislike something like:

if (send_packet(params)) {
do something
}

not just because of the braces but also because an "if" is supposed to
perform a test - not have as a side effect as it might be sending a
packet over the wire.

-- tim
Dec 15 '06 #17
Tim Streater wrote:
In article <fb******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:

>>Double Echo wrote:


[...]

>>>but all the goddam schools preach shitmess roll-up coding and OO. It
works but it's so fucking
messy. You fucking kids think it's cool code, and wow, neato, but then
somebody else has to
work on it, and it's a fucking nightmare. Clean code, nested, and
properly written will allow
the code to be debugged better, and probably survive being re-written
all over again because you
can actually read it. I've gone on to delete code I can't read and just
re-wrote it cleanly.

-DE- ( using my best Dr. House imitation )


Well, if "all the goddam schools" teach it, there must be something to
it, don't you think?


It's just the vogue at the moment. Those of us who have developed a
coding style over 40 years to assist maintainers who might be following,
think different. Cool is not important - maintainability is (and
donkeymentation, of course).
In your opinion, at least. Many others, including us who have been
programming 39 years (started with Fortran II on an IBM 1401) think
differently.

Some old-time programmers get so ingrained in one method it's hard for
them to see a different way of doing things might be better. Others
find new ways to be much better - including easier to maintain.

It's a matter of style.
Personally I dislike something like:

if (send_packet(params)) {
do something
}

not just because of the braces but also because an "if" is supposed to
perform a test - not have as a side effect as it might be sending a
packet over the wire.

-- tim
I love it, and use it all the time. First started doing in in C over 20
years ago. It's one of the great features of languages like C, C++,
Java and PHP, and allows for a lot of flexibility.

In your case the if statement is doing a test - but it's just a test to
see if an action (a dynamic event) completed successfully, instead of
the static value of a variable.

Let's take it one step further:

result = send_packet(params);
while (result) {
do something
result = send_packet(params);
}

Or, just

while (send_packet(params)) {
do something
}

After all, all a while loop is is a test which is executed repeatedly
until the condition fails.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 15 '06 #18
In article <Nt******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:
Tim Streater wrote:
[...]
It's just the vogue at the moment. Those of us who have developed a
coding style over 40 years to assist maintainers who might be following,
think different. Cool is not important - maintainability is (and
donkeymentation, of course).

In your opinion, at least. Many others, including us who have been
programming 39 years (started with Fortran II on an IBM 1401) think
differently.

Some old-time programmers get so ingrained in one method it's hard for
them to see a different way of doing things might be better. Others
find new ways to be much better - including easier to maintain.
I think it's just a vogue. Like when Pascal was the vogue and it was
considered "good" to have only one exit from a procedure. As
excruciating contortions were needed in real-world code to achieve this,
I carried right on using the return statement and ignored the vogue.
Personally I dislike something like:

if (send_packet(params)) {
do something
}

not just because of the braces but also because an "if" is supposed to
perform a test - not have as a side effect as it might be sending a
packet over the wire.

I love it, and use it all the time. First started doing in in C over 20
years ago. It's one of the great features of languages like C, C++,
Java and PHP, and allows for a lot of flexibility.

In your case the if statement is doing a test - but it's just a test to
see if an action (a dynamic event) completed successfully, instead of
the static value of a variable.

Let's take it one step further:

result = send_packet(params);
while (result) {
do something
result = send_packet(params);
}

Or, just

while (send_packet(params)) {
do something
}

After all, all a while loop is is a test which is executed repeatedly
until the condition fails.
If you're doing a test, do a test. If you're sending a packet, send a
packet. These are distinct actions that should be separated.

That's my style, at any rate.

-- tim
Dec 15 '06 #19
Double Echo wrote:
Bill,

Sorry for not getting back sooner... had a lot of work interrupting my
newsgroup time. :-)

Here-doc allows you to basically print out whatever is between the
pattern you choose.

I use ENDOFHTML but you could use ENDOFCODE or whatever.

Perl has a similar construct:

print <<ENDOFHTML;
ENDOFHTML

Notice the semi-colon at the top, PHP is a bit more "correct" putting
the semi-colon at
the end:

print <<<ENDOFHTML
ENDOFHTML;

PHP also uses "<<<" whereas Perl uses "<<".

Anyway, embedded PHP programs were the rave a couple of years ago, and
people were doing
it trying to create really dynamic pages, but it's really messy as
you've found out to do it that way.
It's easier to print <<<EDNDOFHTML because you can actually use ' and "
in the block without trouble. There are also a lot of web servers that
don't like embedded
PHP in HTML docs and will barf or ignore it if you attempt it. So, it's
better to embed HTML in PHP,
and save yourself the hassle. One note, be careful about the placement
at the end, the
end tag _must_ be over at the left, and no space after it, or it won't
work.
THank you. I like to embed the html in the php, but having to
escape all the quotes was killing me - this is much nicer.
bill
>

bill wrote:
>see end of post:

Double Echo wrote:
>>This is old-style dirty PHP programming. There are a lot of stupid
programmers
who mingle/mangle code like this trying to be cute. Instead of some
HTML
with PHP thrown in, reverse it. Have PHP with HTML thrown in. PHP
should be the control, HTML should not be.

<?php

$var = 1 + 1 ;

print <<<ENDOFHTML
<html>
<table>
<tr>
<td>
$var
</td>
</tr>
</table>

ENDOFHTML;

$some_more_php = 2 + 2 ;

print <<<ENDOFHTML
$some_more_php
ENDOFHMTL;

?>

A lot of web servers won't be set up for HTML-with-PHP but if you have
a web server with PHP enabled, you can always throw in HTML.
Programmers
who mix PHP into HTML just don't know how to program cleanly.

-DE-
DE.
for a newbie, who likes your style, please reference or explain the
syntax:

print <<<ENDOFHTML

bill
Dec 15 '06 #20
Tim Streater wrote:
In article <Nt******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:

>>Tim Streater wrote:


[...]

>>>It's just the vogue at the moment. Those of us who have developed a
coding style over 40 years to assist maintainers who might be following,
think different. Cool is not important - maintainability is (and
donkeymentation, of course).

In your opinion, at least. Many others, including us who have been
programming 39 years (started with Fortran II on an IBM 1401) think
differently.

Some old-time programmers get so ingrained in one method it's hard for
them to see a different way of doing things might be better. Others
find new ways to be much better - including easier to maintain.


I think it's just a vogue. Like when Pascal was the vogue and it was
considered "good" to have only one exit from a procedure. As
excruciating contortions were needed in real-world code to achieve this,
I carried right on using the return statement and ignored the vogue.
As I say - in your opinion. Millions of programmers disagree with you.
>
>>>Personally I dislike something like:

if (send_packet(params)) {
do something
}

not just because of the braces but also because an "if" is supposed to
perform a test - not have as a side effect as it might be sending a
packet over the wire.

I love it, and use it all the time. First started doing in in C over 20
years ago. It's one of the great features of languages like C, C++,
Java and PHP, and allows for a lot of flexibility.

In your case the if statement is doing a test - but it's just a test to
see if an action (a dynamic event) completed successfully, instead of
the static value of a variable.

Let's take it one step further:

result = send_packet(params);
while (result) {
do something
result = send_packet(params);
}

Or, just

while (send_packet(params)) {
do something
}

After all, all a while loop is is a test which is executed repeatedly
until the condition fails.


If you're doing a test, do a test. If you're sending a packet, send a
packet. These are distinct actions that should be separated.

That's my style, at any rate.

-- tim
Why? When it makes the code more complicated and harder to understand?

It is a test - a test as to whether the action completed successfully or
not. But this concept is harder for some old-time programmers to grasp.

Just like in my classes - COBOL and FORTRAN programmers had a lot harder
time grasping the concept of pointers as implemented in C than new
programmers did.

And typically the longer someone had been doing structured programming,
the more trouble he/she had in grasping OO concepts.

It's sometimes hard for old-time programmers to change their habits.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 16 '06 #21
Jerry Stuckle wrote:
Tim Streater wrote:
>In article <Nt******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:

>>Tim Streater wrote:


[...]

>>>It's just the vogue at the moment. Those of us who have developed a
coding style over 40 years to assist maintainers who might be
following, think different. Cool is not important - maintainability
is (and donkeymentation, of course).
In your opinion, at least. Many others, including us who have been
programming 39 years (started with Fortran II on an IBM 1401) think
differently.

Some old-time programmers get so ingrained in one method it's hard
for them to see a different way of doing things might be better.
Others find new ways to be much better - including easier to maintain.


I think it's just a vogue. Like when Pascal was the vogue and it was
considered "good" to have only one exit from a procedure. As
excruciating contortions were needed in real-world code to achieve
this, I carried right on using the return statement and ignored the
vogue.

As I say - in your opinion. Millions of programmers disagree with you.
>>
>>>Personally I dislike something like:

if (send_packet(params)) {
do something
}

not just because of the braces but also because an "if" is supposed
to perform a test - not have as a side effect as it might be sending
a packet over the wire.

I love it, and use it all the time. First started doing in in C over
20 years ago. It's one of the great features of languages like C,
C++, Java and PHP, and allows for a lot of flexibility.

In your case the if statement is doing a test - but it's just a test
to see if an action (a dynamic event) completed successfully, instead
of the static value of a variable.

Let's take it one step further:

result = send_packet(params);
while (result) {
do something
result = send_packet(params);
}

Or, just

while (send_packet(params)) {
do something
}

After all, all a while loop is is a test which is executed repeatedly
until the condition fails.


If you're doing a test, do a test. If you're sending a packet, send a
packet. These are distinct actions that should be separated.

That's my style, at any rate.

-- tim

Why? When it makes the code more complicated and harder to understand?

It is a test - a test as to whether the action completed successfully or
not. But this concept is harder for some old-time programmers to grasp.

Just like in my classes - COBOL and FORTRAN programmers had a lot harder
time grasping the concept of pointers as implemented in C than new
programmers did.

And typically the longer someone had been doing structured programming,
the more trouble he/she had in grasping OO concepts.

It's sometimes hard for old-time programmers to change their habits.
I don't know about age being a true component of the argument, it's more
about brain function, some people need object orientated stuff, some don't,
and sometimes it's better to have just the objects you need and the rest
of the app is simply functions. Whatever the need is, not necessarily all
or nothing, this way or that. Sometimes the best of both is really what's
needed. But to suggest that OO is more difficult for old programmers who
do structured programming is a false argument. Most programmers that are
any good have a profit motive and are extremely lazy, so they're going to
do the most efficient thing possible. If I can accomplish an app without
OO you can darn well bet I'll do it without OO unless it's avoidable. It's
like a shotgun for killing mosquitos. On the other hand if I'm part of a
large team and we need the app to have as much components as possible to
build on for the future, OO might be right, but you can still do large
projects without OO. It's a nice feature of PHP to be able to do it
either way. And keep in mind, unless you compile the objects they still
have to be interpreted, and in an interpreted language, speed is everything.
Your OO may actually be too complex and slow the app down, something to
watch for.

Happy Holidays!

:-)

Dec 16 '06 #22
Double Echo wrote:
Jerry Stuckle wrote:
>Tim Streater wrote:
>>In article <Nt******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:
Tim Streater wrote:

[...]
It's just the vogue at the moment. Those of us who have developed a
coding style over 40 years to assist maintainers who might be
following, think different. Cool is not important - maintainability
is (and donkeymentation, of course).
>

In your opinion, at least. Many others, including us who have been
programming 39 years (started with Fortran II on an IBM 1401) think
differently.

Some old-time programmers get so ingrained in one method it's hard
for them to see a different way of doing things might be better.
Others find new ways to be much better - including easier to maintain.

I think it's just a vogue. Like when Pascal was the vogue and it was
considered "good" to have only one exit from a procedure. As
excruciating contortions were needed in real-world code to achieve
this, I carried right on using the return statement and ignored the
vogue.

As I say - in your opinion. Millions of programmers disagree with you.
>>>
Personally I dislike something like:
>
if (send_packet(params)) {
do something
}
>
not just because of the braces but also because an "if" is supposed
to perform a test - not have as a side effect as it might be
sending a packet over the wire.
I love it, and use it all the time. First started doing in in C
over 20 years ago. It's one of the great features of languages like
C, C++, Java and PHP, and allows for a lot of flexibility.

In your case the if statement is doing a test - but it's just a test
to see if an action (a dynamic event) completed successfully,
instead of the static value of a variable.

Let's take it one step further:

result = send_packet(params);
while (result) {
do something
result = send_packet(params);
}

Or, just

while (send_packet(params)) {
do something
}

After all, all a while loop is is a test which is executed
repeatedly until the condition fails.

If you're doing a test, do a test. If you're sending a packet, send a
packet. These are distinct actions that should be separated.

That's my style, at any rate.

-- tim


Why? When it makes the code more complicated and harder to understand?

It is a test - a test as to whether the action completed successfully
or not. But this concept is harder for some old-time programmers to
grasp.

Just like in my classes - COBOL and FORTRAN programmers had a lot
harder time grasping the concept of pointers as implemented in C than
new programmers did.

And typically the longer someone had been doing structured
programming, the more trouble he/she had in grasping OO concepts.

It's sometimes hard for old-time programmers to change their habits.

I don't know about age being a true component of the argument, it's more
about brain function, some people need object orientated stuff, some don't,
and sometimes it's better to have just the objects you need and the rest
of the app is simply functions. Whatever the need is, not necessarily all
or nothing, this way or that. Sometimes the best of both is really what's
needed. But to suggest that OO is more difficult for old programmers who
do structured programming is a false argument. Most programmers that are
any good have a profit motive and are extremely lazy, so they're going to
do the most efficient thing possible. If I can accomplish an app without
OO you can darn well bet I'll do it without OO unless it's avoidable. It's
like a shotgun for killing mosquitos. On the other hand if I'm part of a
large team and we need the app to have as much components as possible to
build on for the future, OO might be right, but you can still do large
projects without OO. It's a nice feature of PHP to be able to do it
either way. And keep in mind, unless you compile the objects they still
have to be interpreted, and in an interpreted language, speed is
everything.
Your OO may actually be too complex and slow the app down, something to
watch for.
First of all, by "old time programmers" I don't necessarily mean age
wise. But I think you have to admit there aren't many 20-something
programmers around who have been programming since 1967, like I have :-)

As for the OO concepts, I have 16 years of corporate training experience
to fall back on. During that time I've trained thousands of
programmers, many in OO languages.

One thing which I've seen repeatedly is the more experienced the
programmer, the harder he/she has adjusting to new concepts.

For instance, COBOL programmers with several years of experience have a
lot of trouble adjusting to the concept of a pointer variable in C/C++.
The same is true with experienced FORTRAN programmers. That's
because those languages don't have pointers.

OTOH, COBOL or FORTRAN programmers with 1-2 years of experience have
less trouble adjusting to pointer data types because they don't have the
preconceived ideas.

The same is true for OO techniques. I didn't say it is more difficult
to learn - but rather it is more difficult for them to overcome
preconceived ideas.

Now I never said OO was right for every circumstance. And I never said
that you had to use OO in every project. But I did say older
programmers have a hard time changing their way of thinking. I stand by
that statement, and so do all of the other OO instructors I know.

Happy Holidays!

:-)

You, too!
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 17 '06 #23
In article <bP******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:
Tim Streater wrote:
[...]
If you're doing a test, do a test. If you're sending a packet, send a
packet. These are distinct actions that should be separated.

That's my style, at any rate.

-- tim

Why? When it makes the code more complicated and harder to understand?
Easier is the word you're looking for. Obviously a typo on your part :-)
It is a test - a test as to whether the action completed successfully or
not. But this concept is harder for some old-time programmers to grasp.
But the test has side-effects. That is my point.
Just like in my classes - COBOL and FORTRAN programmers had a lot harder
time grasping the concept of pointers as implemented in C than new
programmers did.
Never did Cobol, thank goodness. Haven't touched Fortran since 1978.
Since then its been BCPL, C (in large quantities), Z80 assm, and PHP and
JavaScript more recently.

-- tim
Dec 18 '06 #24
Tim Streater wrote:
In article <bP******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:

>>Tim Streater wrote:


[...]

>>>If you're doing a test, do a test. If you're sending a packet, send a
packet. These are distinct actions that should be separated.

That's my style, at any rate.

-- tim

Why? When it makes the code more complicated and harder to understand?


Easier is the word you're looking for. Obviously a typo on your part :-)
Nope, I meant exactly what I wrote.
>
>>It is a test - a test as to whether the action completed successfully or
not. But this concept is harder for some old-time programmers to grasp.


But the test has side-effects. That is my point.
So? There is absolutely nothing wrong with that. You're testing the
results of a dynamic action, not a static value.
>
>>Just like in my classes - COBOL and FORTRAN programmers had a lot harder
time grasping the concept of pointers as implemented in C than new
programmers did.


Never did Cobol, thank goodness. Haven't touched Fortran since 1978.
Since then its been BCPL, C (in large quantities), Z80 assm, and PHP and
JavaScript more recently.

-- tim
I'm surprised you didn't run into a lot of this in your C coding.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 18 '06 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: grid | last post by:
Hi, I recently came across a piece of code like this, ( & ( ( ( some struct * ) 0 ) -> element ) ) ) I had never seen this kind of code being used in any implementations so far, but somehow...
25
by: Alvin Bruney | last post by:
C# is great but it does have some short comings. Here, I examine one of them which I definitely think is a shortcoming. Coming from C++, there seems to be no equivalent in C# to separate code...
192
by: Vortex Soft | last post by:
http://www.junglecreatures.com/ Try it and tell me what's happenning in the Microsoft Corporation. Notes: VB, C# are CLS compliant
6
by: Mike Barrett | last post by:
I am using VS 2005, VB.Net. I need to connect to an FTP server and get a list of files. I plundered the following code from MSDN to accomplish this task. It was part of a class called clsFTP: ...
0
by: seek help | last post by:
Hello, IDE: VS .NET 2003. Problem: Mangled bits of gc class embedded within native C++ class. Description: I have a gc class, BoxedInfo. This wraps a Value type structure, NotiInfo....
6
by: Gerard Flanagan | last post by:
Hello all I would like to do the following: from elementtree.SimpleXMLWriter import XMLWriter class HtmlWriter(XMLWriter, object): def write_raw(self, text): super( HtmlWriter, self...
2
by: toduro | last post by:
Sorry about the bad subject line earlier. What is the right syntax for a C++ declaration which would give me __ls__7ostreamPFR7ostream_R7ostream in an object file produced by the gcc 2.95...
49
by: comp.lang.php | last post by:
/** * Class for grayscaling image * * @author Phil Powell * @version 1.2.1 * @package IMAGE_CATALOG::IMAGE */ class ImageGrayscaleGenerator extends ImageResizeComponents { /
67
by: gator | last post by:
I am quite new to XML and posted a request for example code yesterday. Unfortunately, I did not do a very good job in explaining what I was looking for. Here is an example of a small piece of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.