Drycodez Posted August 11, 2011 Share Posted August 11, 2011 i understand some js codes, but each time i look into someone else's code, am always confuse. Any advise for me? Thanks in advance! Link to comment Share on other sites More sharing options...
thescientist Posted August 11, 2011 Share Posted August 11, 2011 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 More sharing options...
Don E Posted August 11, 2011 Share Posted August 11, 2011 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 More sharing options...
jeffman Posted August 11, 2011 Share Posted August 11, 2011 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 More sharing options...
jeffman Posted August 11, 2011 Share Posted August 11, 2011 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 More sharing options...
Don E Posted August 12, 2011 Share Posted August 12, 2011 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 More sharing options...
Drycodez Posted August 12, 2011 Author Share Posted August 12, 2011 Don E yeah don E, you re wright and am also finding it difficult to unddrstand the cookies stuff...thanks alot DEiRDRED's DAD , DON E, and THE SCIENTIST Link to comment Share on other sites More sharing options...
ShadowMage Posted August 12, 2011 Share Posted August 12, 2011 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 More sharing options...
thescientist Posted August 12, 2011 Share Posted August 12, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.