R
Richard Cornford
Matt said:The point you missed: Not everyone wants to understand
javascript. Some just want to take advantage of its
features by implementing packaged solutions.
And the point you miss is that the wants and desired of an individual
are not, in isolation, sufficient to justify action on the part of those
individuals. There is a reason that responsible parents do not let their
children say up all night whenever they want to, and do not let them eat
what they want to eat whenever they want to eat it. And as adults, when
we are expected to apply some personal judgement in assessing the wisdom
of acting on our every whim, we all live under a legal system that makes
it very clear that some wants should never be gratified.
If people don't want to learn to understand javascript that is fine, all
they have to do is never use javascript. But the desire to use
javascript without an understanding of how to use it has real, harmful
consequences. In a non-professional context those consequences don't
mater too much, people should be allowed to do harm to themselves (only)
if that is their desire, but when someone is being paid (a fee or wages)
there clients/employers have a right to expect them to know enough not
to be doing harm by their actions.
I encountered yet another example of this on Friday when a friend of one
of my mangers, who happens to run his own small business, asked me to
look at his recently re-designed web site and see of there was any
apparent reason why it had dropped out of the Google listings following
the re-design. Apparently he had notices a significant drop in enquires
(in a business where a few enquires now means the possibility of no work
in a couple of months time) and in investigating possible reasons he had
noticed the change in Google's placing of the site, and that the drop in
enquires and change in google rankings had followed the site re-design.
None of the content of the site had changed a word, just the way in
which it was presented. A task undertaken by a 'professional' web
designer in exchange for a fee.
I looked at the HTML of his home page, and I looked for links into the
rest of the site. There were none. Instead all of the navigation into
the rest of the site was handled by a javascript menu, with the link
URLs defined in an external JS file. It wasn't even a complex
(drop-down, expanding tree, or similar) menu, just rollover effects. It
could have been done entirely with CSS that even IE would understand an
act upon. But no, a combination of wanting to use javascript without
understanding it and the availability of a pre-built menu script were
enough to allow a 'professional' web designer to take a fee for
significantly harming the future viability of her client, risking the
livelihoods of its employees and forcing it pay a similar fee to someone
else to rectify the situation.
I can understand that individuals may not want to take time and effort
to learn particular technical skills, but I cannot see that as
justifying their going on to perpetrate unskilled applications of the
technologies when the consequences are so predictably harmful.
Your statement is as ridiculous
Not as a response to the statement of yours that it followed. You have
edited out its context (and failed, again, to mark that eddit).
as saying that if it weren't practical for people to learn
to repair their own cars, we wouldn't have auto mechanics.
It's not, in fact, practical for many people. I didn't say
it was not practical for anyone.
Your statement was: "The idea of spending many hours learning a
programming language is not at all practical". That is a general
statement without qualification, and as the consequences of its being
true contradict the empirical evidence it is therefor a false statement.
I disagree.
You are solving the specific case each time a new one
comes up.
Not each time, only the fist time. Fortunately specific cases do tend to
reoccur on a regular bases. While some of the possible permutations of
the general case may be extremely uncommon.
I find it to be more challenging, rewarding, and beneficial
to try to solve the general case (as much as possible) and
then apply it to the specific case at hand.
You are fixating on the problems of general algorithms. Which is not
that surprising as general algorithms are a prerequisite of general
libraries. The general problem that I am interested in is finding an
optimum code authoring strategy. And one of the issues that I need to
address in achieving that is avoiding the problem of the general
algorithm. The general algorithm may be ultimately re-useable, if it can
actually be achieved, but it is often big, often slow, and sometimes an
impossibility.
In looking at strategies the observation that code is ultimately never
used in a general context allows the issues to be avoided entirely. But
obviously re-writing everything for each specific context is not
efficient, as it eliminates the potential for code-reuse.
My answer to the problem is to build application specific code on top of
re-usable low level components that provide an interface to the
browsers. Such that those low-level components can be specifically
appropriate to the context of their use, but if the context changes they
can be replaced with a different component proving the same public
interface.
The challenge in that is designing an interface that provides the
necessarily information/actions while allowing the component that
provides it to have various diverse implementations.
The result is code that is:-
1. Re-usable, taking advantage of the fact that specific contexts do
reoccur in web development (particularly the common ones).
2. Fast in executing, because it is not trying to take account of
possibilities that are not present in the particular context.
3. Reliable, because it is possible to rigorously test such components
in isolation and so be confident that they do work as designed in the
context for which they were designed.
4. Easily maintained, because changes in their context can be
accommodated by swapping one reliable and well-tested component with
another providing the same interface and so not impact upon any of the
higher level code at all.
5. Small, because excluding consideration of the conditions that do not
apply to a specific context allows the corresponding code to be omitted.
While the general algorithm might be re-usable, and if it is a full and
correct algorithm it may also never need maintaining, but in attempting
to be general it cannot help but be slower and bigger. And rigorously
testing a truly general algorithm means exposing it to all of the
possible permutations, including the ones that are so unlikely that they
may never be encountered in a real context. Indeed, writing re-usable
context specific components as and when needed may mean never having to
tackle the more obscure possible permutations at all, while the quest
for the general algorithm pre-supposes the handling of all such
permutations form the outset.
If someone asks, "how do I find the position of my object
on the page?" and you supply the simplest solution which
will work on their example page, you may not be helping as
much as you could.
I wouldn't respond to such a question by supplying anything.
Such a question would be a joke if it was intended to be a specification
for a browser scripting task, certainly a long way short of something
that could be analysed, designed and implemented.
If the question was asked on this newsgroup it would probably be best
answered with a request for more information. But might instead warrant
a discussion of the properties, object and methods available to provide
position and dimension information, and the factors influencing their
application in determining the absolute position of an element.
It is perhaps significant that you have decided to pick on this
particular task, as you appear to be getting increasingly bitter about
the fact that nobody seems willing to help you write a general
position/dimension reporting algorithm. Though I must remind you that
when you asked the specific question I did tell you that un-resolvable
contradictions made the general position/dimension reporting algorithm
an impossibility. As it happens I have changed my mind about that
because I have seen a was of resolving those apparent contradictions,
but the resulting algorithm is so convoluted that I suspect it would
have to apply a couple of thousand lines of code to each
node/node-ancestor in the DOM. The result might work, but would be too
slow to be practically used in any of the contexts where I have been
interested in knowing elements position/dimensions.
Consider some of the factors involved in the general position/dimension
reporting algorithm:
There is the CSS 'display' property, which may have any of the values;
inline | block | list-item | run-in | compact | marker | table |
inline-table | table-row-group | table-header-group | table-footer-group
| table-row | table-column-group | table-column | table-cell |
table-caption | none | inherit, and any value may be assigned to any
element at any time. So whenever the display value may influence the
calculation of positions and dimensions (which it does) then the
influence needs to be determined on a node by node bases and taken into
account. Of course the odds (even the rational) of someone switching the
display property of an element from 'table-footer-group' to 'compact' in
any real context are extremely low. But that is one of the problems with
the genial algorithm, you have to account for all of the possibilities
or it is not truly general.
Then there is CSS 'position', which may be static | relative | absolute
| fixed, and can also be changed at any point (at least on some
browsers). Combine that with the fact that any element can be moved in
the DOM from one point to almost any other and it is quite clear that
the general algorithm needs to re-calculate the positions and offsets
for each node that it takes into account when calculating positions for
each individual position it calculates.
And the above CSS properties may be mixed with; border-collapse,
border-spacing, empty-cells, float, list-style-position,
list-style-type, marker-offset, table-layout, list-style to produce more
permutations of layout behaviour, and that is without considering the
influence of borders, padding, margins and scrolling.
Summing up the offsetTop/Left of the offsetParents works in the simplest
case, but CSS can have a huge influence on where those offsets are taken
form and the general algorithm needs to be taking that into account.
Abandoning the concept of a general algorithm and working with only the
factors pertinent to an actual context massively reduces the problem,
and allows for possible optimisations in the code that is used. And
doing so with a low level component providing an interface to the
position/dimension information retains the flexibility of the
theoretical general algorithm by allowing the component to be swapped
with one tailored to any other specific context.
Consider, for example, a real context where it is known that no page
elements will have borders, that the HTML and BODY elements will have
zero padding and margins, that all tables will have -
border-collapse:collapse; - and - border-spacing:0; -, that no display
style will be switched from its default to anything but none, and back
again, that no position property will be switched at all, that no
overflow property will be set to auto or scroll and that no element will
be moved in the DOM. The remaining permutations are so reduced that not
only can an appropriate algorithm be easily implemented but it can also
be heavily optimised to minimise the work done to aquifer each
position/dimension.
It may sound like a very restrictive context, but it does apply to a
great many real web sites, and slightly different permutations of
restrictions cover huge numbers of real web sites. All without ever
having to tackle the general problem of accounting for the influence of
all possible permutations.
Tomorrow, if they introduce scrollable areas into their page,
Tomorrow? Real web sites are not radically re-designed at the drop of a
hat. If a design is such that scrollable areas are a possibility then
that is part of the context from the outset, and they may or may not
appear on any specific page. If the design suggests (or the designer
states) that no page divisions will be scrollable then the introduction
of such arias implies a significant re-design. And a significant
re-design is likely to break any pre-existing javascript anyway.
change their layout with CSS, or put some browsers into
standards mode, your solution may break.
It won't break, it will require that the pertinent component be swapped
for one suited to the new context. And given that this happens in the
context of a significant site re-design that is not particularly
unexpected, as whoever deployed the original component understood its
limitations and know the re-design will take it outside its specified
boundaries.
And the person will once again have no idea to fix it,
But If they understood why and how they were using the code in the first
place they would understand how to fix it.
because you gave them a very limited-scope solution which
can't be applied in varied situations.
And what did you supply them with? You gave them code that you clamed
was a general solution (or, more realistically, a 'partial general
solution' (nonsense though such a claim would be)) and it will also
break in the face of particular site re-design changes. And you pretty
much grantee that the individual using your script will not know how to
fix it.
Instead, you can solve the general case which also happens to
solve their specific example.
If you can solve the general case. And assuming that the solution is
viable. I tend to find that when I want to know the position and
dimensions of an element I want that information about a group of
element more frequently than 15 times a second (preferably 24 times).
The bulky, slow, general position/dimension algorithm just cannot
deliver the required performance, because it has to take into account so
much, and do so for each node/node-ancestor.
Then, when their page changes, they don't need to change their
code, because the general solution already considers it correctly.
Again, if you can solve the general case.
The few extra k of
code which is not actually executed in each case is easily
offset by the fact that you don't need to go back and re-visit
the code to solve the new specific case, or change the code
used every time your layout changes.
The stuff that doesn't ever get executed is only the parts that can be
seen to apply to other browsers and the alternatives to things that can
be decided just once and cannot be dynamically changed (such as
standards/quirks mode). The rest, everything that can be influenced by
dynamic manipulation, needs to be re-calculated continuously. The truly
general algorithm must account for all of the possibilities or it is not
general.
The obvious fact to me is that most people prefer the
approach taken by me and many others.
Most people wouldn't have a clue hat you were talking about if you asked
them. This is a question that is only even of interest to a minority of
web developers. So that is a minority of a minority of people.
You may not, and that's fine, because obviously you have
the time and talent to do things your own way.
The question of time is a significant motivating factor in seeking an
effective and efficient strategy. As I have already said, my time is
allocated to projects for the next year, each one with a deadline, and
each followed by another with its own deadline.
... . I don't hear anyone saying, "Thank god I didn't
implement a packaged solution, but instead spent the last
3 months learning and experimenting with javascript so I
could build up my own low-level function library and solve
the specific requirement that I had 3 months ago!"
That is not something you are likely to hear. But you don't have to read
this group for long to see many examples of people who have been using
pre-packed libraries to give the impression that they could use
javascript and have now been asked to do something that they cannot find
pre-packaged and are asking for help meeting a deadline that they could
have met on their own if they had bothered to lean javascript for
themselves in the meanwhile.
Compare it to some every-day examples:
Browser scripting is not directly comparable with everyday examples of
anything. Browser scripting isn't even comparable with any other types
of programming. Remove the downloading issue, the variation in execution
environments and the relatively slow execution and discuss a language
that has its resources on the local computer, provides a known
environment and is compiled into machine code and the library concept
goes form being a dubious idea to being the most sensible strategy
available.
But even so, how many real world examples are there of people providing
professional technical and design services without their accepting a
need to understand what they are doing? And how many clients of such
professionals would not have exactly that same expectation?
When you buy a new TV, do you learn electronics from scratch
and build your own to only have the features you want? Or do
you buy one that costs a little more and has more than you
need, but gives you a TV right away and gives you options in
the future?
The person who needs to learn how to build a television set is
television set designer.
<snip>When you want a new computer, do you research and buy all
the parts separately and spend time assembling them to get
the maximum possible performance?
Yes of course. Computer parts are really easy to assemble, something to
do with the parts being designed to be interchangeable by implementing
common interface standards.
When you choose an OS, do you build it from scratch and make
it consist of the fewest possible features that you need to
use, in order to optimize performance? Or do you use a packaged
solution with lots more functionality than you'll ever need,
which uses more disk space and CPU, but makes your life easier
and more convenient?
Some and some. I learnt the Windows batch installation process years ago
so when I install it I only install the components I want and have my
personal user preferences in place form the fist boot-up.
Using a pre-packaged, generalized solution to a given problem
is not lazy or a cop-out as you seem to suggest.
But selling your services as a creator of javascript using web sites
without understanding what your are doing is as irresponsible as I
suggest. And it is the pre-packaged 'solutions' that make doing so
possible.
It's a realistic approach to take when you consider all the
factors involved and decide that building your own from scratch
just isn't advantageous.
Can someone who is ignorant of the technology they are using take all
the factors involved into account?
Why you object to it as a concept continues to baffle me.
It fails to deliver what it promises. It has directly harmful side
effects. There are better approaches. Why would I stop objecting?
I can only assume that you either have no understanding of the
real problems and priorities faced by many developers in the
world,
I certainly have no understanding of a web developer/designer who would
make an informed decision to do significant harm to their clients.
or that you must dismiss generalized solutions in order to
justify your own work to yourself.
The only people I need to justify my work to are my employers. And given
the pay rise they offered me last week I have to conclude that they are
more than happy with it and definitely don't want me to even think about
working for anyone else.
Incorrect.
Many people can achieve the level of understanding that I,
you, or anyone else has. I understand that many people
don't _want_ to, and many people don't have _time_ to, and
many people have higher priorities. I'm not superior, and
they aren't stupid. They just aren't focused on the same
things as I am, and I see no reason to tell them that they
need to be (as you do).
So having characterised the "average web developer" as a headless
chickens incapable of making informed decisions about the actions they
take, you are now admitting that there is no problem with a lack of
ability.
So we a left with people not learning javascript because they don't want
to. Which is not a problem, they can still practice the skills they do
have. But not wanting to learn a skill is not a reason for attempting to
practice it anyway, and no excuse for the harm that is the likely
consequence of doing so.
Richard.