Ok nerds, get me up to speed on the new web tech. - by SubJeff
Al_B on 30/3/2011 at 22:33
Glad I'm not the only one doing that! I use it more for search engine purposes but I disable javascript, images and CSS periodically to check whether a page is still understandable even if it loses its presentation.
SubJeff on 31/3/2011 at 07:15
I do this too. Doesn't everyone? I use 3 or 4 divs to layout my pages, typically. Title, menu, content and sometimes a footer. Without CSS it looks silly but everything is readable (dependent on JavaScripting/PHPing of course).
In other news I've finally read all the chapters in my Java book that I need I think. I'm missing out the GUI stuff (apart from event handling) and web app/applet stuff for now and on re-reading the Android stuff boy does it make more sense now I get all the Java chat.
I know the Android books state you should know Java or OOP of some sort at the start but I was disappointed that the Sams book isn't as hand-holding as the Sams Java book. I need hand-holding!
deathshadow on 31/3/2011 at 08:37
Quote Posted by Subjective Effect
PS. Regarding Java and JavaScript. As I said I'm only halfway through this book. Am I correct in thinking that classes in Java are essentially functions in JavaScript?
No, classes are like, well.. classes in Javascript, C++, or PHP. Now, they can contain METHODS, which are the same thing as functions...
A "class" is just a prototype to an object. It lays out what functions and variables are available and establishes scope for when you actually create an object instance.
Think of it as the same thing as a TYPE declaration... Which again is where objects in Wirth languages make more sense, since an object is just an overglorified record... record being the equivalent to a C struct.
It's easier to explain using object pascal/modula.
You have type definition, and a variable declaration.
Code:
type
glFloat=double;
var
myVar:glFloat;
myVar is now type glFloat, which is an alias to type double.
Now, let's step up the ladder to a record (struct in C)
Code:
type
glPoint:record
x,y,z:glFloat;
end;
var
myPoint:glPoint;
begin
myPoint.x=10;
myPoint.y=20;
myPoint.z=50;
end;
The type declaration just makes a complex variable type, "record" which has three properities (think of them like a field in a table). Declaring the type doesn't create the variable in memory... declaring a variable of that type does.
Which brings us to an object:
Code:
type
dudeType=object
position:glPoint;
speed:word;
constructor init;
procedure show;
destructor term;
end;
var
enemy:array[0..3] of dudeType;
you:dudeType;
I'll skip the actual 'working' parts of the code, but declaring the object doesn't make it exist until you assign it to a variable -- or multiple variables... which is the beauty of objects. Constructors and destructors are special methods (functions) that are called when the element is created or destroyed. (something that annoys me about php -- no destructors called when doing unset)
A Java/C++/PHP "class" is just their version of an object delcaration. You are declaring a complex variable type, that then gets assigned to a variable... or even multiple variables.
I consider it VERY hard to learn objects without the intermediate step of understanding a record/struct or strict typecasting -- which is why you rarely see well coded objects in PHP and many other languages that had objects shoe-horned into them as an afterthought... thankfully It's my understanding Java was at least designed with objects in mind, but being a C/AT&T dialect offshoot I'd be skeptical about how well it's implemented... especially given the HORDE of properties the root object type has by default.
Which goes hand in hand with the ridiculously loose typecasting.
SubJeff on 31/3/2011 at 10:34
I suppose we could debate this all day but the reason I was equating a function to a class is that in JavaScript when you create a function you can then send arguments to it in the same way as you can send them to classes.
The way I was taught JavaScript, many moons ago, was that methods are built in, like the getElementById() method of the document object, and functions are user created methods (that can, of course, use other methods).
For example; in the code I posted a change() function is created. It's purpose is to take the an argument when you click a button thus - onclick="change('form1') - and then to alter the display property of form1 to 'block' whilst switching all the other forms display property to 'none'.
Simple.
But although this is a function can it not also be considered a method? And is a class necessarily a prototype of an object? Can it not also just be a block of code? Or does that block of code automatically become an object?
deathshadow - could you post your examples in Java instead of pascal? It'd make it easier for me to understand.
Al_B on 31/3/2011 at 12:05
Quote Posted by deathshadow
something that annoys me about php -- no destructors called when doing unset
Strange - they work fine for me. Which version of PHP are you using?
Quote Posted by deathshadow
Which goes hand in hand with the ridiculously loose typecasting.
I've had limited experience with java but my understanding is that it's very strictly type checked and closer to Pascal than C++ in that respect.
Quote Posted by Subjective Effect
I suppose we could debate this all day but the reason I was equating a function to a class is that in JavaScript when you create a function you can then send arguments to it in the same way as you can send them to classes.
No, you don't send arguments to classes - you send arguments to functions which are members of an
instance of a class.
As deathshadow said: First, you define the class - the functions and variables it contains. Next you create one or more instances of that class using
new. You then interact with the class by executing it's functions or accessing its data. Each instance of the class is a separate entity with its own local data.
Quote Posted by Subjective Effect
But although this is a function can it not also be considered a method? And is a class necessarily a prototype of an object? Can it not also just be a block of code? Or does that block of code automatically become an object?
The function can be considered a method
in the specific case of javascript because when defined it will be a member of the window object. However, that doesn't make the function an object or a class which are different concepts. Reviewing the basics may well be of benefit (e.g. from the (
http://download.oracle.com/javase/tutorial/java/concepts/index.html) Java Tutorials website).
Javascript
does support objects - but not traditional class inheritance, polymorphism or information hiding. Prototypes and closures are probably the closest that I've seen in the language - however, I suspect you're not quite at that stage just yet.
inselaffe on 1/4/2011 at 13:05
On a side note, does anyone know a html / xml / whatever editor where i can edit an opening or closing tag and it will also edit the corresponding tag? As this seems a very simple feature that i have not yet found out how to do - it's quite annoying. Maybe i just don't know how to activate it, at least in bluefish.
Functions and methods are exactly the same thing. You are more likely to hear them called methods when talking in an object orientated sense and functions in a procedural or functional sense.
Really no idea how you have equated a Class to a function but like others have suggested, i would try to start at the beginning and perhaps try a different java book. If it's an introductory book on java that doesn't teach you the concepts of object oriented programming then that's rather strange and worrying. Java tutorials Al_B suggested should help hopefully.
Also from a much earlier note, you can actually make web pages in xml. To do this, you create an xml file, where the tags can be anything you like (a real advantage of xml - but i suppose also a disadvantage when there is no real standardisation). Creating the xml file is a bit like making a database but a lot more lightweight and easier.
You then use an XML style sheet (xsl) in order to define how the xml file is displayed to the user. This can not only process the xml, picking out only what you need, but it also can contain html - so html 5 and css3 and anything you like.
As others have said and i think you mentioned, try to do things in CSS wherever possible as opposed to javascript. CSS3 allows a lot more to be done in CSS as opposed to javascript in this regard.