LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Which language separates code and HTML more readable? (https://www.linuxquestions.org/questions/programming-9/which-language-separates-code-and-html-more-readable-921723/)

Mr. Alex 01-03-2012 03:11 AM

Which language separates code and HTML more readable?
 
Hello!

Is it JSP or Perl?

I was learning and coding PHP for about 6 months and I start hating it. It's like for little kids, plus it doesn't separate HTML and the code itself which makes everything a bloated mess. So I started to think what else do we have for normal web-programming. Java for Web sounds very interesting. How readable is it compared to Perl? Is it also separated from HTML?

Doc CPU 01-03-2012 04:24 AM

Hi there,

Quote:

Originally Posted by Mr. Alex (Post 4564413)
Is it JSP or Perl?

I know neither of them intimately, so my answer can only be a very general one. I do know PHP very well, however.

Quote:

Originally Posted by Mr. Alex (Post 4564413)
I was learning and coding PHP for about 6 months and I start hating it. It's like for little kids, plus it doesn't separate HTML and the code itself which makes everything a bloated mess. So I started to think what else do we have for normal web-programming. Java for Web sounds very interesting. How readable is it compared to Perl? Is it also separated from HTML?

In the context of web programming, you use all these languages to do some action on the server, plus communicate with the client by generating HTML code. So the HTML must be contained in your PHP/Perl/Java code in one or the other way - maybe embedded and mixed, maybe as a template in a separate file. I don't see how PHP, Perl and server-side Java could be significantly different in that point. You can create a horrible mix of spaghetti code in PHP, but you can also create very clean, structured code.

So I'm convinced that the clarity and structure of code isn't a matter of the programming language, but a matter of the programmer's discipline.

[X] Doc CPU

rigor 01-03-2012 04:59 AM

I have used all of what you've mentioned, and quite a but more, extensively for web pages. Since you appear to have mixed elements in your question, that tend to be used at different levels in web page applications, I'm not quite sure what you're going for here.

I can say, that I have seen plenty of JSP's and so called JSP documents, that are rather painful to read.

I much prefer an approach than uses something like Velocity Templates. Instead of nesting several "languages" all delimited with "<" and ">", Velocity uses the much more visually distinctive "#" to introduce its VTL ( Velocity Template Language ) elements. Also, although JSP's allow embedded Java, including conditional statements to further conditional the use of elements in a JSP, Velocity does not.

The tendency is for people to write cleaner files.

Mr. Alex 01-03-2012 05:33 AM

So you're saying there is no separation of code and layout in PHP/Perl/JSP? There are little pieces of information on different forums where people say something like "PHP's biggest problem is that it can't separate code and layout". Something like that. And it sounds like others can do it. What do those quotes mean?

And there is one more thing that makes me hate PHP: it has 4000+ functions and they have no system in naming. Man! How many sort function of PHP are out there? Such a mess you will never remember in your life. So if Perl or JSP have something more beautiful and readable for eyes, I wanna go with one of them.

Recently I read some examples of Perl working with MySQL DBs - so clean. Looks several times cleaner than PHP's working with MySQL.

Cedrik 01-03-2012 06:33 AM

There are ways to build PHP classes that could clean the code, also using good HTML layout helps (use CSS divs layout rather than tables)

Mr. Alex 01-03-2012 06:44 AM

Cedrik, thanks.

What about Ruby? How well is it suit for server-side web-development?

rovf 01-03-2012 09:11 AM

Quote:

Originally Posted by Mr. Alex (Post 4564568)
Cedrik, thanks.

What about Ruby? How well is it suit for server-side web-development?

I find RubyOnRails appealing:

http://www.sitepoint.com/ruby-on-rai...k-at-the-code/

http://guides.rubyonrails.org/getting_started.html

dugan 01-03-2012 09:17 AM

You want something with a server-side templating language.

Django (HIGHLY RECOMMENDED Python framework):
https://docs.djangoproject.com/en/1.3/topics/templates/

ASP.NET MVC (C# framework for SQL Server/IIS deployment):
http://www.asp.net/mvc/videos/mvc-3/...or-view-engine

Mustache (available for most languages):
https://github.com/bobthecow/mustache.php

Google Closure templates (Java):
http://code.google.com/closure/templates/

Twig (for PHP):
http://twig.sensiolabs.org/

(And yes, Ruby on Rails and Velocity too. But that's been mentioned).

resetreset 01-03-2012 10:16 AM

I developed ONE website in Perl, and I was about to collapse at the end of it. No idea how lazy I am compared to others, but that's what happened to *me*. I had to put huge amounts of HTML in Print statements, it was an absolute NIGHTMARE.
I hadn't known much about PHP at that point, but then I did and started liking it, so I used it for my next site (which was finished about 1 yr. 6 months after the other one!!!!)

Making pages which look artistic on the SERVER is, well, .... a fine art! I want more money for it than this kind of job currently pays, so.....

My heart and soul is elsewhere, but I also can't resist the urge to tamper with the world from the corner of my bedroom (and my sites are GOING to do that, I'm going to MAKE them!) :)


Just a little heart-to-heart, would appreciate yours! :)

resetreset 01-03-2012 10:19 AM

Just to add, something that occurred to me while I was reading dugan's Django page, as to where my heart IS - well, how about a *Flash* frontend communicating with a PHP script or whatever? :)

Would I end up a millionaire doing that? :)

rigor 01-03-2012 05:39 PM

Quote:

Originally Posted by resetreset (Post 4564780)
Just to add, something that occurred to me while I was reading dugan's Django page, as to where my heart IS - well, how about a *Flash* frontend communicating with a PHP script or whatever? :)

Would I end up a millionaire doing that? :)

There is plenty of Flash in use on the front end already. I've seen little "glitches" occur with a variety of browsers and OS platforms, that concern me. Also, to me, often the integration doesn't feel quite as seamless as with other approaches.

Overall, in a sense, I prefer not to physically work harder, but instead to find a better way to do things.

I tend towards automation, and/or code generation, as long as the result is at least as good as a Human could accomplish following "Best Practices". That usually leads towards something involving templates.

One of the things I've done with which I was fairly happy, combined Velocity, HTML, CSS, Javascript, Java but not JSP's, and Perl.

Java was used to write code to process data, once the data was past the web layer.

Some of the Java code was hand written, and the CSS, but templates were also written, which could be used to create much Java code for the server side, as well as plenty of HTML and Javascript for the front end. A fair amount of the SQL for the server side was also generated from templates. Multiple layers of code in various languages were generated. Since they were done from templates, templates created by Humans, you wouldn't necessary be able to tell the hand crafted code apart from the generated code, if the generated code hadn't labeled as having been generated.

Originally it was done in the early days of Velocity when we didn't necessarily have a lot of the other platforms we have today.

But now we have a variety of the options which have already been mentioned.

Mr. Alex 01-04-2012 02:41 AM

I think I found what I might need - Python.

Python was intended to be a highly readable language. It is designed to have an uncluttered visual layout, frequently using English keywords where other languages use punctuation.

I'm a little surprised noone suggested this option...

frieza 01-04-2012 02:58 AM

php can be written with a significant separation of code and HTML, if you use a templating engine like

phplib, which provides a templating engine
http://sourceforge.net/projects/phplib/

smarty, another php based templating engine
http://www.smarty.net/

in fact here is a list of 10 templating engines for PHP
http://www.webresourcesdepot.com/19-...plate-engines/

separation of code and html really depends alot on how the program is written, not just on the language used.

Mr. Alex 01-04-2012 04:59 AM

Thanks frieza.
But I am neither interested in templating engines nor in frameworks. Just a pure language.
And no matter how well organized can PHP be - it's still disgusting.

Mr. Alex 01-04-2012 05:00 AM

Thanks frieza.
But I am neither interested in templating engines nor in frameworks. Just a pure language.
And no matter how well organized can PHP be - it's still disgusting.


All times are GMT -5. The time now is 12:27 AM.