Jump to content

Good Coding Rules - was Case statement structure


Skysnake
 Share

Recommended Posts

Quote

The rule is that Case statements with most events should be in top of the list.

From From here, bottom of the post

I am not arguing the logic of this, merely would like to point out that if there is such a rule, it is not documented...  Are there other such rules?

Skysnake

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

It isn't a rule, but something you can consider in any on-the-fly interpreted language. Consider this simple sequence:

If <Condition> Then
    [13,000 lines of code]
Else
    [Action]
End

It's obvious that, unless a form of compilation has taken place which can jump direct to [Action] when <Condition> isn't met, the interpreter will have to read and ignore 13,000 lines, something which wastes time. Hence if you expect the false branch to be significantly more frequent than the true branch, you should swap them and negate Condition.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  1. Follow Modular design patterns in general. Split things into small autonomous units. Never  glom everything into a monolithic structure. (this one is important. Having one place to edit in case of changes instead of many files to edit. maintainability)
  2. Use good meaningful variable names
  3. Don't get carried away with macros, not to say don't use them
  4. Keep functions small, over 50 lines and you need new supporting functions (this works well with C/C++/C# but not sure if applicable to AutoIT and otehr scripting languages, but I try to do this with AutoIT. Most of what makes my functions longer are just logging if they get long in AutoIT cause I am a logging fool
  5. Don't follow the Single Entry Single Exit nonsense bullcrap either. If you run into a condition you need to break from the function, then do it
  6. Don't use GoTo statements (obviously they lead to spaghetti logic that can't be maintained)
  7. Use Constants for strings and stuff that does not change. that way, when something needs to change, it changes in one spot, not many
Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • Moderators
1 hour ago, Skysnake said:

Thank you. Perhaps this thread should live with the "good coding practice" posts?

Are there any other such? (eager to learn) :)

 

I would agree. Why not add them to the existing thread below rather than starting another.

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I added the note about order of Case statements in relation to code in a WM_NOTIFY message handler. This is important for a message handler which handles a huge number of events which is the case for a virtual listview.

This is in accordance with the warning under remarks for GUIRegisterMsg function in the help file. GUIRegisterMsg is used to create the message handler.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...