Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / tidying up your DBPro code.

Author
Message
jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 12th Apr 2007 23:20
You may be like me, and when programming, end up with code which is not "tidy". Ie for tabbed in line with its next, and a more indented tab for any repeat untils which are inbetween, or do loops etc.
I am trying to write some "parsing" code so that progs are tidied up.
Am I wasting my time as there is already such a prog out in cyberspace somewhere?
Cheers
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Apr 2007 23:27 Edited at: 12th Apr 2007 23:33
Yes there is. Program attached.

It was written back in 2001 well before DBPro appeared and as such has only been tested on DBC.

Please let me know how you get on with it with DBPro!

TDK_Man

Attachments

Login to view attachments
jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 12th Apr 2007 23:54
Thanks TDK.
A quick run shows it works. however, you cannot choose how much indent for one thing. I'll continue my parsing - it keeps me off the streets...
Perhaps, when it is "finished", I could put it on line and ask for comments, criticisms etc?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th Apr 2007 00:33
Quote: "A quick run shows it works. however, you cannot choose how much indent for one thing."


You shouldn't need to. The program I wrote uses the 'standard' two spaces for each indentation.

In my opinion, more than two spaces makes it much harder to read and with deeply nested statements, they soon disappear off the right side of the screen.

TDK_Man

Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 13th Apr 2007 01:02 Edited at: 13th Apr 2007 01:04
That is a very smart and useful little program. Do you think indentation should be in tabs (so it's a changable width) or strictly spaces? I'm using CodeSurge, it can convert tabs to spaces but not spaces to tabs.

Listen to TDK, indentation width 2 is The One True Indentation Style. (At least for DB and DBP anyway)

By reading this sentence you have given me brief control of your mind.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 13th Apr 2007 01:46
:/ I thought the standard was 3 spaces...

SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 13th Apr 2007 01:56 Edited at: 13th Apr 2007 01:59
Quote: "I thought the standard was 3 spaces"


I always use three spaces, as that's how many DarkEdit did... but Strangely, VB does four spaces by default (but it can be changed), A Double-indent by Barrie's standard! (well, VB 98 did anyway, never needed a newer version than VB 98...)
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 13th Apr 2007 02:34 Edited at: 13th Apr 2007 02:34
Dbp standard ide does 3, codesurge does 4. I think 2 is too few.

Who needs a signature?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th Apr 2007 08:52
I based my 'standard' comment on what was done back in the dawn of time many, many years ago when I started programming in Forth and Pascal.

Purely by experimenting, I personally prefer 2 spaces - mainly because it doesn't force too many line ends off the screen when your nested loops are more than a few deep.

The whole (and only) point of indentation is to make the code more readable by making certain blocks of code stand out so you can see missing Nexts and Endifs etc, so if 2 spaces work, why use more?

It's a matter of personal choice at the end of the day and if anyone would find it useful, I'm quite happy to add an option to the above DBA Tidy program so you can set the amount of indentation.

TDK_Man

SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 13th Apr 2007 10:28
In theory, one space is good enough, so long as you know that a one-space indent is not accidental, that may be where the two-spaces idea came from.

Also, if for whatever reason, your working on say, a work computer, and your network admin has put a ridiculous quota on you... two spaces saves a bit of memory over the 3 or 4 space indents... Saves a whole 1-byte each time of your, say 10 million-byte restriction... "Every little helps..."
jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 13th Apr 2007 10:37
V interesting!
The tidy prog really is a neat, useful one, TDK_man. It works with my DBPro. I will stop writing mine, particularly if you are going to make the tab count a selectable number. Could it be selected and then made "permanent" in a sort of ini file?
Do you still have your source code then - you must be tidier than me? What language was it written in?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th Apr 2007 17:23
Quote: "Do you still have your source code then - you must be tidier than me? What language was it written in?"


Yes - I tend to keep everything. The main problems are actually finding the CD something was backed up on when you need it - or discovering it's corrupted when you eventually find it!

That particular program was written in Delphi.

TDK_Man

Master Xilo
18
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bern, Switzerland
Posted: 13th Apr 2007 23:01
this program would be more useful if you could set the amout of spaces made
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Apr 2007 04:15
Here you go then... I've attached V1.2!

A quick note though:

DB doesn't use a keyword to define the start of procedures (like it does with functions) - it uses labels.

The problem with this is that DBATidy has no way of knowing if any given label is the start of a procedure or just a plain label. This probably won't affect most of you, but I tend to add lots of labels in my programs at key places so I can use F9 to quickly jump to them.

Take the following for example:



The program has no way of knowing that the PrintHello label is the start of the procedure and has an associated Return, or equally that the DataLabel label does not.

So, for DBATidy to work there's one small rule:

All labels in your program that are the start of a procedure must be the only thing on that line (you can add a Rem on the end of labels which really are only labels): Eg:



Using this method, only PrintHello will trigger indentation.

TDK_Man

Attachments

Login to view attachments
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 14th Apr 2007 04:32 Edited at: 14th Apr 2007 04:33
How the program decreased in size after a new feature was added is beyond me... We are seeing the death of bloatware.

By reading this sentence you have given me brief control of your mind.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Apr 2007 05:44


The new version is optimized and compressed - the old one wasn't.

TDK_Man

jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 14th Apr 2007 12:45
It's great that you have produced another version of DBAtidy.exe with indent selection, and so quickly!
I wouldn't fancy creating such an interface page in DBPro - I suppose that is because it is first and foremost for games-writing.
I'm surprised tho', with all the logic which there must be in your prog, it does not indent Print "Hello" even tho' the "for" in print " this is a for " does not indent:-

PrintHello:Rem dccxvxdv
Print "Hello"
print " this is a for "
Return

DataSection: Rem This really is a label
Data 1,2,3,4,5

Surely looking for a Return statement after a ":" would show it up as either a procedure or just a label?
It is no more difficult than ignoring the keyword "for" in the line print " this is a for ", and not indenting it?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Apr 2007 19:05
jayell leedham:

Sorry, I don't understand what you are saying... especially when I explained the reason why labels which start a procedure must be on a line on their own.

If DB used the keyword 'Sub' for example as in:



... just like the keyword Function used with functions, there wouldn't be a problem. As it is, in DB, normal labels and labels which define procedures are identical.

Quote: "Surely looking for a Return statement after a ":" would show it up as either a procedure or just a label?"


And how far would you check after said label? What if it wasn't a procedure, but there was a procedure many lines down? How do you know that procedure's Return doesn't belong to a different label?

And what about multi-statement lines?...

Sync On: Sync Rate 0: CLS 0

Are you suggesting that those two colons should trigger a scan for two Returns?

Quote: "It is no more difficult than ignoring the keyword "for" in the line print " this is a for ", and not indenting it?"


I suggest that you continue writing your version (as stated in your second post in this thread) and see if you still think the same when you've finished it!

TDK_Man

jayell leedham
18
Years of Service
User Offline
Joined: 24th Jan 2006
Location: North Yorkshire
Posted: 15th Apr 2007 19:50
Apols.
Great prog tho'.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Apr 2007 19:57
No problem!

A lot of programming tasks look dead simple... until you actually try to code them!

TDK_Man

Login to post a reply

Server time is: 2024-11-25 19:25:14
Your offset time is: 2024-11-25 19:25:14