Overclock.net banner
1 - 16 of 16 Posts

·
Registered
Joined
·
1,766 Posts
Discussion Starter · #1 ·
Hi guys,

I'm developing a website right now. As it's a personal website, I want to make parts of it "fancy". I know javascript is a great way to do this and I've heard alot about Javascript and Jquery.

When would you say it's ok to use Jquery? I want to learn whilst doing this website and I've read that it's ok to use jquery for some really advanced stuff but if it's simple, code the javascript yourself. Would you agree?

Considering I want a nice fancy website, are there any tutorials or websites you guys would recommend?

Thanks
smile.gif
 

·
Registered
Joined
·
1,314 Posts
jQuery is Javascript, it is simply a Javascript Library to make things easier to do.

For example, doing this in Javascript:

Code:

Code:
var x = document.getElementsById('my-id')
Is the exact same as this in jQuery:

Code:

Code:
var x = $('#my-id')
Once you have that (it is a DOM object), both javascript and jQuery will work with it the exact same way (because it is the same). Therefore, at any given point, you can jump in between and use what is best.

Say I want to get an ID of the first div on the page, then get the id, then add another word to it, I would do this:

Code:

Code:
var div = $('div:first'); //use jQuery here, because this selector is much easier to work with
var id = div.prop('id'); //once again, jQuery here because it is simpler (IMO)
var newId = id + 'aNewWord'; //now this is 'normal javascript
Remember, jQuery is Javascript, you don't have to choose. You aren't choosing between them, you use them in tandem, mix-and-match.
 

·
Premium Member
Joined
·
1,601 Posts
Quote:
Originally Posted by stupid View Post

jQuery is Javascript, it is simply a Javascript Library to make things easier to do.

For example, doing this in Javascript:

Code:

Code:
var x = document.getElementsById('my-id')
Is the exact same as this in jQuery:

Code:

Code:
var x = $('#my-id')
Once you have that (it is a DOM object), both javascript and jQuery will work with it the exact same way (because it is the same). Therefore, at any given point, you can jump in between and use what is best.

Say I want to get an ID of the first div on the page, then get the id, then add another word to it, I would do this:

Code:

Code:
var div = $('div:first'); //use jQuery here, because this selector is much easier to work with
var id = div.prop('id'); //once again, jQuery here because it is simpler (IMO)
var newId = id + 'aNewWord'; //now this is 'normal javascript
Remember, jQuery is Javascript, you don't have to choose. You aren't choosing between them, you use them in tandem, mix-and-match.
this
Provided that you have some non-javascript programming experience. If you don't you will need to learn the basics of programming before using jQuery.
 

·
Registered
Joined
·
28 Posts
Writing everything in JavaScript by yourself is like inventing the wheel again (and again). Using frameworks like jQuery or Dojo is a good thing to do, but you also have to watch out, especially with jQuery plugins. jQuery plugins are usually written by third parties and if they're dead, it could mean that if you update jQuery, you have to look for an alternative plugin with the same features (and do some refactoring).
 

·
Registered
Joined
·
1,678 Posts
Well it depends what it is, but usually using jQuery makes a lot more sense. The point of any programming library is to save time rewriting complex functions over and over again.

Also there are tons of free jQuery CDNs you can use so it won't even cost you additional bandwidth loading the library.
 

·
Fantastic Mr Fox
Joined
·
5,862 Posts
Quote:
Originally Posted by stupid View Post

For example, doing this in Javascript:

Code:

Code:
var x = document.getElementsById('my-id')
Is the exact same as this in jQuery:

Code:

Code:
var x = $('#my-id')
Not quite. The jQuery equivalent would be:

Code:

Code:
var x = $('#my-id').get(0)
You jQuery example returns a jQuery object, not a DOM object. The two are not directly interchangeable but are easily convertible, since the jQuery object is more or less a wrapper for zero or more DOM objects which provides lots of nice functionality that you don't normally have OOTB.

As for the topic at hand: I would say that it is always ok to use jQuery unless you can write custom JavaScript that is simpler for your specific situation. However, it's a good idea to understand a bit about what jQuery is doing behind the scenes, especially if you start attaching lots of functionality to browser events that get fired very frequently, or doing things in lengthy loops (try to avoid both in the first place). There is often a very small syntactic difference between jQuery that is fast and jQuery that is slow. What you place inside the magic $() can wildly affect how jQuery finds elements, for example.

Of course while you should always try to use "best practice", spending days optimising something that is technically slow but which is imperceptibly slower than something that is technically fast is a waste of time.

Oh dear, I think I got lost in my own ramblings.
 
  • Rep+
Reactions: ritetek

·
Registered
Joined
·
1,314 Posts
Quote:
Originally Posted by wedge View Post

It doesn't do anything that you can't do yourself. So, if you're doing it for learning and practice then it's probably better to code it all yourself.

I always try to keep 3rd party code to a minimum. So personally, I never include jquery unless I'm already using some other 3rd party code that requires it.
With that logic, just dump your OS and write everything in assembly.
 

·
Registered
Joined
·
985 Posts
Quote:
Originally Posted by stupid View Post

With that logic, just dump your OS and write everything in assembly.
That's... not... quite... what I said...
The dude wants to learn. You don't learn much if you just copy/paste other people's code. Or at least you don't learn the right things anyway. When developers learn to be dependent on third party libraries, that's where big, ugly, bloated, poor-performing apps come from. I'm not saying anything bad about jQuery, I'm speaking generally here.

Let me sum it up differently:
First learn how to do it yourself. Then you'll be smart enough to know when to use helper libraries, and when not to.

It's the whole 'give a man a fish' vs 'teach a man to fish' philosophy...
 

·
Premium Member
Joined
·
8,041 Posts
Quote:
Originally Posted by wedge View Post

That's... not... quite... what I said...
The dude wants to learn. You don't learn much if you just copy/paste other people's code. Or at least you don't learn the right things anyway. When developers learn to be dependent on third party libraries, that's where big, ugly, bloated, poor-performing apps come from. I'm not saying anything bad about jQuery, I'm speaking generally here.

Let me sum it up differently:
First learn how to do it yourself. Then you'll be smart enough to know when to use helper libraries, and when not to.

It's the whole 'give a man a fish' vs 'teach a man to fish' philosophy...
I'm inclined to agree with you.

While I'm fully in favour of copy and pasting code, I do think it makes a lot of sense to do the basics without jQuery first. Then as sites evolve and become more complex, port it over to jQuery. That way you understand the foundations and will be in a better position to understand what's going wrong when jQuery misbehaves.
 

·
Registered
Joined
·
985 Posts
Quote:
Originally Posted by Plan9 View Post

While I'm fully in favour of copy and pasting code
A few lines here and there is fine of course, we all do that.
What I meant by that, is that it's not okay to copy/paste big chunks of code if you don't fully understand what it does. If you would not be able to produce the same thing on your own, then you have no right to use it.

I had some pretty strict programming teachers back in university. They would not accept any assignment that had any third party libraries in it. I used to do that, I would find some free libraries online with some really cool looking controls I wanted to use, or themes or whatever. But if I had handed anything in with those included, I would have been marked zero. They said "how do you know there's not any malicious code hiding in there?". But I think they just used that as an excuse. They wanted me to learn, not take shortcuts. And it worked, I figured out how to do most of the same things on my own. And the compiled size of my program was less than half of what it was when it had the extra libraries included.
 

·
Premium Member
Joined
·
8,041 Posts
Quote:
Originally Posted by wedge View Post

If you would not be able to produce the same thing on your own, then you have no right to use it.
Well no, that's just dumb. I cannot program an OS yet I'm more than happy calling POSIX or Win32 headers. At some point you have to trust other developers.

I just think you're right about learning the basics of a language before been spoon-fed with all-singing and all-dancing frameworks.
Quote:
Originally Posted by wedge View Post

I had some pretty strict programming teachers back in university. They would not accept any assignment that had any third party libraries in it. I used to do that, I would find some free libraries online with some really cool looking controls I wanted to use, or themes or whatever. But if I had handed anything in with those included, I would have been marked zero. They said "how do you know there's not any malicious code hiding in there?". But I think they just used that as an excuse. They wanted me to learn, not take shortcuts. And it worked, I figured out how to do most of the same things on my own. And the compiled size of my program was less than half of what it was when it had the extra libraries included.
The size thing is worth noting; particularly given the context of web development. It's the main reason I don't use jQuery myself. (though another part of it is I like to know how everything works).

I'm going to ignore the malicious code comment though because you don't need to borrow libraries to have malicious code inserted into your projects.
 

·
Registered
Joined
·
28 Posts
Quote:
Originally Posted by wedge View Post

That's... not... quite... what I said...
The dude wants to learn. You don't learn much if you just copy/paste other people's code. Or at least you don't learn the right things anyway. When developers learn to be dependent on third party libraries, that's where big, ugly, bloated, poor-performing apps come from. I'm not saying anything bad about jQuery, I'm speaking generally here.

Let me sum it up differently:
First learn how to do it yourself. Then you'll be smart enough to know when to use helper libraries, and when not to.

It's the whole 'give a man a fish' vs 'teach a man to fish' philosophy...
When you're writing programs and doing all the stuff yourself, the next person that have to maintain your code will probably have a bad time if you didn't use a framework. I mean, as a Java developer I never wrote an application for business that doesn't use a framework. A framework like the Spring framework is something I use all the time... you won't see me writing my own MVC framework, or a framework to do dependency injection.
There are a lot of things in the Spring framework I'm not able to write.

You of course need the basics, but if you read most development job requirements, next to the basics there is also a gigantic list of frameworks you need to know before you can apply to that job. jQuery is a pretty popular, well known framework that is on some of those lists, so it doesn't hurt to know jQuery. Doest it mean you need to know how to write it yourself in JavaScript, not at all.
Maybe it is still possible to do that for a framework like jQuery, but if you start with enterprise JavaScript frameworks like Dojo, it will be a lot harder.

Development is really evolving from a phase where every developer could write frameworks by themself to a phase where frameworks are more important to increase maintainablity, readability, ... . When having that view on the IT world, it's logical that not all new developers know how to write frameworks by themself.

A decade ago I would probably have agreed with your post, but IT has evolved since then and so did the frameworks.
 

·
Registered
Joined
·
985 Posts
Quote:
Originally Posted by g00glen00b View Post

When you're writing programs and doing all the stuff yourself, the next person that have to maintain your code will probably have a bad time if you didn't use a framework. I mean, as a Java developer I never wrote an application for business that doesn't use a framework. A framework like the Spring framework is something I use all the time... you won't see me writing my own MVC framework, or a framework to do dependency injection.
There are a lot of things in the Spring framework I'm not able to write.
Well I'm certainly not saying that frameworks should never be used. There are plenty of circumstances that more than justify their use. Above a certain scale then they almost become mandatory as you say. But I'm sure you could write it yourself if you REALLY wanted to.
thumb.gif

Most of my work is on smaller scale, and I usually own all my own code. In this situation there's less of a case to support using frameworks.
Quote:
Development is really evolving from a phase where every developer could write frameworks by themself to a phase where frameworks are more important to increase maintainablity, readability, ... . When having that view on the IT world, it's logical that not all new developers know how to write frameworks by themself.
Again, I'm not saying they should never be used. Just that there is right time and place to use them, and that would certainly qualify. My school of thought probably is a little bit old-school, cause I am! But all I was trying to say in the first place is that new developers should not use those tools while they are learning, because then they become dependent on them. You should be at a certain level of development experience before you work on anything of such complexity that necessitates their use.
 
1 - 16 of 16 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top