Code Behind vs not

A

Alan Silver

Therefore, you can have your cake and eat it!

Actually, there's nothing clever about that.

What *is* clever is if you can eat your cake and have it!!
 
A

Alan Silver

I was answering A question. Not THE question.

OK, see if you can answer this one ...

Three men take two days to dig a hole deep enough to fill with seven
bathtubs of water. How many beans make five?
 
K

Kevin Spencer

Hi alan,
You seem to agree that there aren't any benefits.

Not at all. I consider the whole argument to be Lilliputian in nature. I
don't agree or disagree. To me, it's a meaningless question.
As an aside, I actually like calculus. I guess that's the way my mind
works. I have a PhD in Mathematics, so I'm a bit biased!!

I KNEW there was something I liked about you! ;-) For my own edification, I
just built a Mandelbrot Set Generator. Email me and I'll send you a copy. It
includes a Complex Number class, that is still in progress, but it can add,
subtract, and multiply Complex numbers (so far). In fact, my Mandelbrot
Generator doesn't use these methods; it uses simplified algebraic equations
derived from the Calculus.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
K

Kevin Spencer

Five?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
A

Alan Silver

Five?

Darn, I knew I shouldn't have used that Bumper Book Of Easy Questions in
this newsgroup!!
 
A

Alan Silver

Hi alan,
Not at all. I consider the whole argument to be Lilliputian in nature. I
don't agree or disagree. To me, it's a meaningless question.

OK, that's a better way of putting it. It was what I meant, but phrased
in a way that pleases me more ;-)
I KNEW there was something I liked about you! ;-) For my own edification, I
just built a Mandelbrot Set Generator. Email me and I'll send you a copy. It
includes a Complex Number class, that is still in progress, but it can add,
subtract, and multiply Complex numbers (so far). In fact, my Mandelbrot
Generator doesn't use these methods; it uses simplified algebraic equations
derived from the Calculus.

Sounds right up my street!! When I was at university, I wasted enormous
amounts of resources producing Mandelbrot prints on the university's
plotter. The prints were about four feet square and took most of the
night to generate.

Mind you, that was back in the days when a computer as powerful as my
outdated PC here would require a fair-sized room and air conditioning!!

I'll e-mail you privately for the program.
 
K

Kevin Spencer

Well, Alan, this app is a bit quicker, but it uses a recursive function to
resolve the Z value, and it will generate a stack overflow if you go past
about 4096 iterations. Still, at 4096 iterations, you do get some beautiful
imagery, and to create a 440X440 image (I've been testing at that size), it
can take up to about 5 minutes (at 4096 iterations). Of course, it can
generate an image of any size, up to the limit of the size of a bitmap.

You should also appreciate the coloring. It uses a custom gradient I
developed, which has no tertiary colors. It starts at RGB0,0,64 (Dark Blue)
for a single iteration, and the colors blend "warmer" as it approaches the
limit. Blue to purple to pink to red to orange to yellow to white, very
smooth. All members above the limit (in the set) are colored black by
default.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
A

Alan Silver

Well, Alan, this app is a bit quicker, but it uses a recursive function to
resolve the Z value, and it will generate a stack overflow if you go past
about 4096 iterations. Still, at 4096 iterations, you do get some beautiful
imagery, and to create a 440X440 image (I've been testing at that size), it
can take up to about 5 minutes (at 4096 iterations). Of course, it can
generate an image of any size, up to the limit of the size of a bitmap.

You should also appreciate the coloring. It uses a custom gradient I
developed, which has no tertiary colors. It starts at RGB0,0,64 (Dark Blue)
for a single iteration, and the colors blend "warmer" as it approaches the
limit. Blue to purple to pink to red to orange to yellow to white, very
smooth. All members above the limit (in the set) are colored black by
default.

Sounds good, I can see whole days being wasted playing with it instead
of doing some real work!!

I await the code ...
 
G

Guest

This may ramble a bit, as I am writing it on the fly. Hope it starts to
illuminate the concepts.

First, let's understand that .NET uses an OO methodology. What this means is
you design your objects as classes. Your tagged page is derived from your
CodeBehind, which is derived from System.Web.UI.Page. If you do not use
CodeBehind, you still derive from System.Web.UI.Page, but this fact is hidden
from you.

TO better understand OO, you have to start thinking in objects. The easiest
way to understand the concept, for me, is to think in terms of financial
markets. In the financial world, you have commodities and securities.
Commodities are actual physical items, like corn, oats, cattle. The commodity
market, ultimately, is involved with selling these items (yes, this is
getting to OO, just hold on). Securities represent real world concepts that
are not physical. When you own stock in a business, you have a security. You
cannot walk up to the physical location and take a brick, as the ownership is
an abstract concept.

Now to OO. Classes are blueprints to represent objects. When you run a
program, you make an instance (instantiate) of a class; this is an object.
The objects can be physical (like a commodity), like employees, customers,
books in inventory, etc. These are easy to identify. They can also be
abstract (like a security), like orders, processes, etc. In a fully OO
system, objects interact with objects.

Your web page, for example, contains a variety of objects, most of which are
controls. The web page, itself, is also an object.

Now, where OO pays off. When you create a new web page, there are events
that the system goes through. These events are set up in both
System.Web.UI.Page, as well as other classes in the hierarchy (ultimately
ending on System.Object). When you create a page, you can effectively ignore
most of the events, as the system is handling setting up the page for you.
The one you normally do not ignore is Page_Load, but even this is a built in
abstraction for System.Web.UI.Page.Load() (built into the compiler).

When you drag and drop controls on a page, or write the tags in your ASPX
file, you inherit all of the benefits of having the System.Web.UI.Page class
underneath. The page will parse and render HTML, as the ability is built in
underneath the hood. The page will handle events, like Page_Load and run the
code you have there (also built in to the class hierarchy). Each of the
controls will render correctly in the browser and you have a built in caching
mechanism called ViewState.

Now, try to imagine a non-OO ASP.NET world. The closest I can come to (real
world) is writing your entire application in JavaScript embedded in an HTML
page. Don't think this is real? Open a page, insert a bunch of controls with
events to handle them. Open the page in a browser and View Source. Look at
how much client side code is written for you that you simply inherit as part
of the framework.

Back to the topic of the thread. When you embed everything in the page, you
lose the direct connection to System.Web.UI.Page, as the connection is
slapped on by the ASP.NET engine to make your page work. While you still have
the inheritance, you are largely typing blind and debugging by running the
application in a browser. In addition, the tools cannot help you, as the
tools are built for a direct inheritance chain, not an implied chain (this is
getting better in the next version of Visual Studio, of course) - what I mean
here is there is no Intellisense or any other help if you need to poke down
to base class functionality. This is not a problem with simple applications,
but becomes critical as applications get more complex.

Another benefit of code behind is you can run compile on your application
rather than debug in a browser. The code will throw compiler errors, which
you can fix before you deploy. WHen you embed in the page, you end up
debugging in browser, which means you have to deploy somewhere to actually
see what is going wrong. In addition, there are no debuggers for embedded
code. At your present stage in development, you may not see this as
important. Once you get used to using debug tools, however, you will
instantly notice the increase in speed in coding and in finding errors.

By the way, one thing you should learn to use, that will save you tons of
time "debugging" a production application, is tracing (the Trace class). It
only runs when tracing is on, so it is not major overhead in a correctly
working system.

I may have confused the issue more than helped it (hope not), but my time is
up for now.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

One of the biggest benefits is to abstract away the logic of how the UI works
from the actual presentation itself (i.e. HTML, XHTML, WML, etc.). One
example where this is a huge problem is ASP/HTML - yuk!

The other big benefit is code re-use. In .NET you can have your pages
templated so that each page inherits its visual implementation from a single
"master page". If you ever have to change the appearance, you just change
the master page, not all 30 pages or whatever your site might have. Let's
say you have a common UI validation method that is used by all of your pages,
if you don't use the code-behind concept, you'll be stuck doing something
*stupid* like using include files - or worse yet, copying this method into
every page that uses it. Can you say maintenance nightmare?

If you know anything about OO, you'll realize the benefits right away.

Dave
 
M

Matt Berther

Hello Dave,

Codebehind should not be mistaken for having classes. If you have a common
validation method, perhaps the codebehind is not the right spot for it, but
rather a ValidationHelper class.

This class can be accessed from either the code-behind or inline.

Don't get me wrong, I absolutely prefer code-behind. I just want to make
sure that people are aware that you can still realize the benefits of OOP
without using it.
 
T

tshad

Matt Berther said:
Hello Dave,

Codebehind should not be mistaken for having classes. If you have a common
validation method, perhaps the codebehind is not the right spot for it,
but rather a ValidationHelper class.

This class can be accessed from either the code-behind or inline.

Don't get me wrong, I absolutely prefer code-behind. I just want to make
sure that people are aware that you can still realize the benefits of OOP
without using it.

Here, here Matt.

This is the point we have been trying to make for awhile in the quest for
opinions on behind vs inside.

We all see benefits of OO. I haven't heard anyone say anything against
that.

The problem was in differentiating the discussion between the two.

Tom
 
J

Juan T. Llibre

re:
If you know anything about OO,
you'll realize the benefits right away.

Are you talking to me ?

I was pointing out that the argument has been
deliberated to exhaustion, not only in this thread
but in other threads.
 
A

Alan Silver

I was pointing out that the argument has been deliberated to
exhaustion, not only in this thread but in other threads.

Not that this point will stop us from continuing to debate it for many
days to come ;-)

We may even get into the Usenet book of records for the longest and most
boring thread ever!!
 
T

tshad

Alan Silver said:
Not that this point will stop us from continuing to debate it for many
days to come ;-)

A little debate is good for the soul :)

Of course, if a little debate is good for the soul, what's a lot of debate
good for?

Tom
 
A

Alan Silver

I was pointing out that the argument has been deliberated to exhaustion,
A little debate is good for the soul :)

Of course, if a little debate is good for the soul, what's a lot of
debate good for?

Filling up the day, whilst avoiding doing any real work!!
 
T

tshad

Alan Silver said:
Filling up the day, whilst avoiding doing any real work!!

I wouldn't say - "not doing any real work"

What about the benefit you get from mental stimulation? :)

Tom
 
A

Alan Silver

Of course, if a little debate is good for the soul, what's a lot of debate
I wouldn't say - "not doing any real work"

What about the benefit you get from mental stimulation? :)

Well, it keep me awake I suppose, but then if I wasn't doing this, I
could just as well go to sleep anyway as I'm not actually doing any
work!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top