Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 13 Jan 2012 03:55 PM |
I have been looking on other programming sites and what I've realized is that few people on this site even attempt to make their code readable or understandable.
Bad code:
for i,v in pairs(script.Parent.Parent.Parent.Parent:GetChildren()) do if v.Name:match("Asdf") then return v end end
There is no way ANYONE who reads this will have no idea what you are actually trying to do. You name your variables arbitrary things like "asdf" which only makes it harder to understand.
Good code:
local Player = script.Parent.Parent.Parent for _, stringvalue in ipairs(Player:GetChildren()) do if stringvalue.Name:match("KOs") then ...
See what I mean? You should name your variables what they do, not necessarily the generic i, v and such.
What do you think? |
|
|
| Report Abuse |
|
|
|
| 13 Jan 2012 03:58 PM |
| I would have to agree, but if we are only making the code for ourselves it wouldn't really matter because we're the only ones reading it. |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 13 Jan 2012 04:01 PM |
| Except that a lot of people post their code on the forums... |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
|
| 13 Jan 2012 04:04 PM |
@1WOOF1;
True, but stringvalue makes more sense because he hasn't yet added the if statement that checks if it is KOs, so if he had it as KOs, it wouldnt make sense to say if KOs.Name:match("KOs") then- . |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 13 Jan 2012 04:08 PM |
Another reason to write understandeable code is that you may have to look back on your code later. If it's written all in 1-character variablesyou're gonna have to spend way too much time relearning it.
On the other hand, if you name your variables properly you will be able to remember quickly.
When I wrote my 1k line script for Catalog Heaven a few months ago, and came back, I realized it was a horrible mess and had to start from scratch. |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 13 Jan 2012 04:23 PM |
You probably don't forget your code because at most you write about 50 lines.
When you are writing 1000+ lines, it is important to write good code.
It's good to get into the habit of writing your code so it can be easily read by you and others. It may prove useful someday. |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 13 Jan 2012 04:33 PM |
There's no point in trying to convince you. As you get older you'll eventually realize that there is a point to writing clear code.
Somehow, I would rather believe people who've had decades of experience in computer programming over you. |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 13 Jan 2012 04:35 PM |
"for i, Good code: for _, "
Hahhaha...
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 13 Jan 2012 04:37 PM |
"if v.Name:match("Asdf") then" Good code: "if stringvalue.Name:match("KOs") then "
What? If you mean bad code because it's logically stupid, then sure, the first one it obviously going to win.
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 13 Jan 2012 04:39 PM |
So I take it you guys are the guys who backspace all the whitespace and comments in your code to make it more efficient? Do you choose to use 1-character variables to make your code faster?
That's what I thought. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 13 Jan 2012 04:41 PM |
I don't use comments in my code, have a pretty good memory, I do use short names for useless variables, but not for variables already assigned, or of importance.
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 13 Jan 2012 04:42 PM |
"1-character variables to make your code faster?"
No, but it allows you to write code much quicker.
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 13 Jan 2012 04:44 PM |
"in pairs" "ipairs"
Why would you use ipairs, though.
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
| |
|