Jump to content

Help!


Drycodez

Recommended Posts

keep reading and learning. Good developers write concise but clearly legible code. It's most likely the syntax and style. The more you learn the more you will be aware of. Perhaps if you provided examples we could explain them to you.

Link to comment
Share on other sites

It's like that for me too Samuel sometimes. I understand pretty much most or all when it's well written, put together neatly and use variables that are well named. I've seen some JS code that looks like a bunch of blob text put together and I'm saying to myself.. "where do I begin..?" When I see code like that, it can be a little discouraging to learn or continue with JS, but I still go at it. The same goes for some PHP code I read sometimes, especially over at php.net where users can contribute their interpretation of a function there or something like that. Can be confusing, yes.What I like about w3schools tutorials is that they are well put together, easy to understand and grasp what's going on within the code, but yes even some code at w3schools can be a bit confusing. For example, these past few days I've been looking into JS cookies and the tutorial at w3schools on that was a bit confusing. For instance this can confuse a novice/beginner:

var i,x,y,ARRcookies=document.cookie.split(";");

That's taken from w3school cookie tutorial. When I first saw that, I thought to myself "hmm what?". It looks like the variables i, x, y and ARPcookies are set to document.cookie.split(";");. My conclusion is that all the variables are being assigned the samething being split by ';' If anyone wants to give their input on that, I would appreciate it. Anyhow, normally what I do is go line by line and when I see something I don't understand, I look it up in the JS references or google. If I can't get it no matter what, then I ask on here for example. No matter what though, especially if it's your passion, as thescientist said, "keep reading and learning". :)

Link to comment
Share on other sites

Close, but there is only one assignment. These are equivalent:

var i,x,y,ARRcookies=document.cookie.split(";");

var i;var x;var y;var ARRcookies=document.cookie.split(";");

The first version takes up less space and keeps the code a little neater. You'll hear arguments about efficiency, but I'm not convinced.

Link to comment
Share on other sites

O. Samuel.Experiment. If you see a whole bunch of stuff you don't understand, select just the FIRST thing that confuses you and try to see what it does. Because I help out so much on this board, I have a lot of experimental documents just sitting on my desktop. If I need to try something new, I will keep it small and separate to see how it works.It is often very hard to see what something does when you see it in the middle of a lot of other confusing stuff. That's why I like to pull things apart. I debug the same way. I am often surprised when people post a hundred lines of code on this board and they didn't know they had a problem until they test all 100 lines--because they never tested the little pieces! Crazy.

Link to comment
Share on other sites

Ah yes I knew about putting variables onto one line but in that code, the only variable being actually set is ARRcookies correct?I just wasn't sure if it was a efficient way(for neatness) OR an efficient way of assiging the same value to many variables at once. Thanks for clarifying that DD!

Close, but there is only one assignment. These are equivalent:
var i,x,y,ARRcookies=document.cookie.split(";");

var i;var x;var y;var ARRcookies=document.cookie.split(";");

The first version takes up less space and keeps the code a little neater. You'll hear arguments about efficiency, but I'm not convinced.

Link to comment
Share on other sites

I just wasn't sure if it was a efficient way(for neatness) OR an efficient way of assiging the same value to many variables at once.
It is efficient for declaring multiple variables and (as DD said) saving space. You can assign a single value to multiple variables in a similar fassion:var x = y = z = 5;Variables x, y, and z will all equal 5.
Link to comment
Share on other sites

also, if the kind of code you are looking at is library code (like jQuery) or something like that, make sure you aren't reading their production code. It is often compressed and striped of whitespace, comments, and any meaningful variable names by reducing them to simple character variable names. Often their dev code is properly formatted, has meaningful variable and function names, and comments.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...