#116457 - 2004-03-19 08:05 PM
Re: Tips to stay organized when coding?
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
as an arts major, you should stick to asking if someone wants to supersize their meal.
OK... a few things
when I write an IF statement, I'll write the IF and then ENDIF, and then fill the parameters in
the same goes for Function/endfunction, for next, do while etc...
I will do similar things for quotes:' ' or " " and then fill it in.
UDFs should go to the end of the script, to get them out of the way.
Make sure to use lots of comments to describe the logical steps in your code
|
Top
|
|
|
|
#116458 - 2004-03-19 09:11 PM
Re: Tips to stay organized when coding?
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Quote:
I'm a noob at KiX (all programming really) but a veteran at being disorganized. I start KiX projects that I can hardly read the next day. Does anyone have tips or links to help me organize a project beforehand and stay organized during?
I know about properly labeling variables and functions, but does anyone actually map out their program beforehand, a script for their script if you will? I know this is probably Computer Science 101 but I was an English major!
i once had a 12th grade public school teacher make us write out on pen and paper and get it approved by her the entire program before we even got a change to type it in to the computer (BASIC on a Apple IIe)
the really sad thing about that class... i think i knew more than the teacher... and to top it all off... the class that i HAD to take in the 12th grade, was the same class that i look as a intro to computer science in the 6th grade while in a different school system.... BASIC on a apple IIe......
As for keeping orginized.... use white space TAB, space, line returns to organize your code. Use comments.... Don't try to GOLF your code right away... take your time... spread out get to know the logic behind the process you are trying to do before you look at condensing it.
Also as of late...i find my self programming more and more UDF's that call other UDF's.... this lets me compartmentalize my code, break it down to small chucks that are easier to handle. This type of behavior is really apparent in KixForms scripts!
|
Top
|
|
|
|
#116460 - 2004-03-19 09:42 PM
Re: Tips to stay organized when coding?
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
probably from you spending so much time looking at sheep
|
Top
|
|
|
|
#116462 - 2004-03-19 10:37 PM
Re: Tips to stay organized when coding?
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Shawn,
Was this the sign your sister put on your door after school?
|
Top
|
|
|
|
#116463 - 2004-03-22 10:58 AM
Re: Tips to stay organized when coding?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Well, asking is a good sign that you are on the right track.
Some varied rambling thoughts...
Scan the FAQs for some guidelines on coding techniques and good practices. They are not hard and fast rules - some are personal preferences and some have evolved through discussion, but they make an excellent starting point.
If you find yourself using "GOTO" when you know that the modern pedantic coder considers it an anathema don't fret - you are learning and you will not know how to avoid it in some situations. When you post the code and are lambasted for such an appallling lack of coding grace you can ask how to code it differently, and you will learn something new
Get a piece of paper and sketch out your objectives. Start with the high level and get a loose definition of the process down. Use your artistic talents and produce a flow-chart.
Break down the high level process into tasks - keep the task descriptions very short.
Doing this beforehand will naturally lead you into laying out your program as a series of tasks, sections or modules. This will tend to encourage your code to be organised.
You may also see common or similar tasks appearing repeatedly in your process - these are opportunities for User Defined Functions.
Now you have an idea of what you want to do, you should be able to look at the processes and make sure that you know what you need for each task - gather together information about server names, directory paths, WMI or ADSI objects, the format of data files or user input and so-on.
Once you have that all together, you might as well getting something in your script file. Rough out the script by putting in comment sections that mirror your tasks, and define all your User Defined Functions - the actual code will come later.
At the top of every script you start, include the following lines: Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("ASCII","ON") $=SetOption("WrapAtEOL","ON)
You may want to take out the BREAK ON when the code goes into production, but leave it in while developing.
You should also try to avoid using variables within strings and set the option:
Code:
$=SetOption("NoVarsInStrings","ON")
DIM all your variables near the top of your script, and avoid GLOBAL variables. GLOBAL variables are useful for static (constant) information and to maintain stateful information for UDFs, but are rarely needed and will cause you trouble if you rely on them.
Give your variables meaningful names - there are good recommendations for a protocol called "short form hungarian notation" in the FAQs.
Indent your code. It is not vital that you choose tabs or spaces, but be consistant in both the characters and the number that you use for each level of indentation. When you add or remove code, take time to go back and fix the indentation if it has changed - you will find that this alone will trap many of the common errors like IF without ENDIF.
Work on each of the tasks in your script one at a time where possible - don't try to write the entire script at the same time. Once you are happy that the section is clean, accurate and as good as it is going to get you can move on to the next.
When you come to complex tasks, write down the detail on paper in pseudo-code. This is just a simple English description of the process which you can translate directly into script once you have a better idea how it is going to work.
If you have any really complex code that you think will take a few attempts to get right, take just the complex process and work on it in a temporary script. When you have worked it out and are happy, transfer it into your main script.
The most important thing is to have a clear idea of the layout of the script before you begin. Once you are experienced you will do this in your head for simpler scripts, but while you are learning get it on paper first.
|
Top
|
|
|
|
#116464 - 2004-03-22 06:43 PM
Re: Tips to stay organized when coding?
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Well, first and formost (especially after Radimus said "as an arts major, you should stick to asking if someone wants to supersize their meal."), know that IT people have a strange sense of humor. Assume we're teasing/busting first.
Second, write comments in your code - lots of them. In some of my larger projects, you will find up to 45% of the file is comment text! I usually can't remember what I had for breakfast by the second cup of coffee, so don't expect me to remember why I coded it that way 9 months ago!
Third, use meaningful variable names. Personally, I like to use CAPS for GLOBAL and MixedCase for Local var names. Find a general style you are comfortable with and stick with it. Look at other peoples code to see how it is laid out, decide what you like/don't like and adopt the best.
Fourth (should be first, but had to reference the others) - Never take Lonk's advice verbatim! (see - there's the sarcastic humor!) He'll tell you to use no comments, minimal spaces, no indents, and single-character var names! He covers the "Good" and "Ugly" parts of the "Good, Bad, and Ugly" trilogy, and codes everything for a KixGolf project! It's great code, if a bit uncomprehensible.
Finally, Richard's comments are right on target. Many of us write and even respond to questions in "pseudo-code" - a mix of code, logic, and descriptions of what we haven't yet decided how to code. It's a great way to organize your ideas, and pseudocode often becomes the comments in your code.
Welcome to the board..
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#116467 - 2004-03-23 10:57 AM
Re: Tips to stay organized when coding?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
No a bad idea - also maybe start a "Diary of a KiXtart noob" in the general topics forum, I always enjoy reading those
A guide from a starters perspective would be quite useful. By the time we think about writing an FAQ it's because we know most of the As to the Qs. This means that the documents can be dry and hard to read as we assume that the reader has a level of understanding which they may not.
The FAQ forum is moderated, so once you have something that you think is suitable, have a word with one of the forum moderators and get some advice on format.
Be prepared for your work to be criticised and debated - you are after all proposing to produce a document which is going to set out best practices for fellow starters, so it needs to be clear, accurate and uncontentious, and we can be quite vigorously opinionated around these type of subjects.
I hope I haven't put you off as it is worthwhile and you will find that your time and effort spent to give something back to the KiXtart community will be appreciated.
|
Top
|
|
|
|
#116468 - 2004-03-23 02:20 PM
Re: Tips to stay organized when coding?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Quote:
I've seen beginner tips sprinkled throughout the existing FAQs like KiXtart Starter's Guide and Best Practices and Methods but I think a more comprehensive beginner's guide is in order.
Maybe, but this is definitely worthwhile - The Start to Finish Guide to Scripting with KiXtart
What the Author and Ruud have done with this book is break it down in to it's most vital components and show how each goes together. From editors or functions to macros and examples of each.
Thanks,
Kent
|
Top
|
|
|
|
#116469 - 2004-03-31 12:19 AM
Re: Tips to stay organized when coding?
|
mrwumpus
Fresh Scripter
Registered: 2003-09-04
Posts: 14
Loc: California, USA
|
Can anyone here personally recommend that book ("The Start to Finish Guide to Scripting with KiXtart")? There's just one review on Amazon.com and I was hoping for feedback from people on here about it. Would it be particularly helpful to a newbie?
_________________________
Jason
|
Top
|
|
|
|
#116470 - 2004-03-31 01:48 AM
Re: Tips to stay organized when coding?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
The thing that is good about the book is that it takes the approach that it does not talk down or talk up to you. It is a good read and guide no matter your expertise.
Kent
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 557 anonymous users online.
|
|
|