Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Is there a way to use less divs in HTML?

HTML

  • Please log in to reply
36 replies to this topic

#13 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 24 October 2011 - 07:23 PM

In all seriousness: look at the source code of this page. Count the divs on it. Compare it to what you had.

Divs provide a logical separation and grouping of data. Depending on the complexity of your page's structure, you will need more or fewer. As long as you have the right number for representing your page's structure, it's fine.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#14 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 24 October 2011 - 08:09 PM

So basically the right way is the way that works, if I understand this right, in programming.
  • 0

#15 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 25 October 2011 - 05:58 AM

I'd qualify it a little: In programming your project must
1) work (otherwise, what's the point?)
2) be efficient enough for the domain needs (calculating pi to a trillion digits is not overly speed dependent, guiding an airplane to land can't have a 1 minute refresh)
3) be coded clearly enough to maintain (super-efficient code that everyone is afraid to touch is not a great idea)
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#16 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 25 October 2011 - 06:35 AM

The latter, about the super-efficient code :lol: LOL; when I program in assembly, I don't like such super-efficiency; I like to make things in my style, and I think my style is easier to read, too.
mov eax, dword [ebp-4] 

mov ebx, eax 

mov eax, dword [ebx] 

...

  • 0

#17 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 25 October 2011 - 07:21 AM

I was actually being serious. Part of refactoring is clarifying code, or at least adding comments for the next person.
  • 1

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#18 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 25 October 2011 - 02:50 PM

Oh, I did take you seriously. It's just the last part:

... (super-efficient code that everyone is afraid to touch is not a great idea)


I just got reminded of the time when I tried compiling a C program, and then disassembling the object file; it was very hard to follow. So it's just I got reminded of that, and of the thing that I usually don't like to make code too efficient to read.

I, myself, don't always add comments, but I like having things in my own style (which is not necessarily the fastest way), which I usually understand. For example, I like to use ENTER and LEAVE, rather than the manual 'push ebp' , 'mov ebp, esp' , etc., prologues and epilogues.

So yeah, I just wasn't sure of what would be the right smiley face to use.

* * *

And as for HTML, to relate more to the topic of this thread, just because this takes up less space on disk:
<html><head><title>Something</title></head><body><h1>Hello World!</h1><div id="some_div">Hello, how are you?</div></body></html>
, it doesn't mean that it's easily readable or editable.

Now, this is easier to both read and edit:
<html> 
	<head> 
		<title> Something </title> 
	</head> 
	<body> 
		<h1> Hello World! </h1> 
		<div id="some_div"> 
			Hello, how are you? 
		</div> 
	</body> 
</html>

Note: It is hard to make indented code using something like (Windows) NotePad or WordPad; that's why it's better to use a source code editor, like SciTE or Notepad++, which not only keeps track of the indentations, but also highlights the syntax, so it's easier to read the code (by the way, I'm not a source code editor salesman).
  • 0

#19 hoku_2000 _99

hoku_2000 _99

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 25 October 2011 - 03:49 PM

This page had A LOT of divs. I think I only have about 4 or so. I do feel that I have the right number on my page in my opinion. This was actually my first time seeing a page with so many divs.
  • 0

#20 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 25 October 2011 - 10:58 PM

Just 474 divs before this post. Propably a few more after this one :)

Edited by wim DC, 25 October 2011 - 10:58 PM.
typo

  • 1

#21 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 26 October 2011 - 05:51 AM

Oh, I did take you seriously. It's just the last part:

I just got reminded of the time when I tried compiling a C program, and then disassembling the object file; it was very hard to follow. So it's just I got reminded of that, and of the thing that I usually don't like to make code too efficient to read.

I, myself, don't always add comments, but I like having things in my own style (which is not necessarily the fastest way), which I usually understand. For example, I like to use ENTER and LEAVE, rather than the manual 'push ebp' , 'mov ebp, esp' , etc., prologues and epilogues.

So yeah, I just wasn't sure of what would be the right smiley face to use.

* * *

And as for HTML, to relate more to the topic of this thread, just because this takes up less space on disk:

<html><head><title>Something</title></head><body><h1>Hello World!</h1><div id="some_div">Hello, how are you?</div></body></html>
, it doesn't mean that it's easily readable or editable.

Now, this is easier to both read and edit:
<html> 
    <head> 
        <title> Something </title> 
    </head> 
    <body> 
        <h1> Hello World! </h1> 
        <div id="some_div"> 
            Hello, how are you? 
        </div> 
    </body> 
</html>

Note: It is hard to make indented code using something like (Windows) NotePad or WordPad; that's why it's better to use a source code editor, like SciTE or Notepad++, which not only keeps track of the indentations, but also highlights the syntax, so it's easier to read the code (by the way, I'm not a source code editor salesman).


I think this is actually a great example of why it can be a good idea to have a processing step before you put your code out on the web. All the whitespace in the second version has a very real cost. It can increase the size of the page by 5-10%, which increases server bandwidth, which increases server costs, and wait time for users, and delay serving pages when under heavy load...

I've got a web-app I maintain, where I actually "compile" the server-side code, in the sense that I do a lot of processing from the source that I edit to the source we distribute to our customers. It's pretty easy to do, and can save a lot of very real dollars.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#22 hoku_2000 _99

hoku_2000 _99

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 26 October 2011 - 03:21 PM

WOW!!! Now that is a lot.
  • 0

#23 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 26 October 2011 - 07:06 PM

...to the source we distribute to our customers...


Hmmm... Customers? Is thy website an online store?




WOW!!! Now that is a lot.


What is a lot?




... where I actually "compile" the server-side code, ...

A "compiler" is good; a "decompiler" would be nice too, however.
  • 0

#24 hoku_2000 _99

hoku_2000 _99

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 26 October 2011 - 07:23 PM

What is a lot?


Divs being used on this site. :thumbup:
  • 0





Also tagged with one or more of these keywords: HTML

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download