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.

AppGameKit Classic Chat / I'd really like to see OPTION EXPLICIT (I mean REALLY)

Author
Message
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 24th Sep 2013 12:35 Edited at: 24th Sep 2013 12:38
I wonder if anyone else feels the same as me on this issue ...

I've been using TGC products since day one, which is nigh on 13 years. In that time, I can honestly say 95% of my bugs are caused by mistyped variable names. So the vast majority of my frustration and time wasting is spent on wondering what the hell I've done wrong, when I've simple got a single character wrong in a variable name. It really is a totally unnecessary pain to go through.

I'd really love to see an optional switch, like VBs Option Explicit (not used that in years, but I think that's right) which would force you to define all variables before they can be used. I don't care what the engine does under the covers. Sometime like this:

Where as this ...

... would complain that fEatenAmount# hadn't been defined. I don't care if fEatenAmount# is defined globally.

I know this isn't an extremely easy fix, but I'm fairly sure under the covers AppGameKit scans the source file, finds all unique variable names based on scope and defines them up front. What I'd like it to do is, if the program is headed with an 'OPTION EXPLICIT', and it encounters a variable like 'fChickenRadius#' without encountering a 'fChickenRadius# as float' first, it'll whinge at compile time.

That'd basically cut 10% off my development time and make the experience significantly more pleasant.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Sep 2013 13:13
i agree, OPTION EXPLICIT or strict is a must have.
the next target is v2, maybe paul can change something for us.

there exists a lighten name concur in editor (min. 3 chars)

or you can use user defined types as alternative.

with beta 19 the udt as parameter and return values working now.
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 24th Sep 2013 13:17
Yep, UDTs are a bit of a life saver. The 3 chars highlighting also helps for checking, but I often use temp local variables like iX or fX#, which don't get highlighted.

It'd definitely be very useful. I think when it's been mentioned in the past with DBP it has been dismissed because it's not necessary, it's just a 'nice to have'. Personally I think it's one of those small changes that will make the language feel more robust and credible.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 24th Sep 2013 13:54
The trouble is that Basic allows for undeclared variable names on the fly. Most languages do not. In C, C++ or Pascal, you cannot reference a variable that has not been defined. All it needs is a STRICT compiler instruction, and any undeclared reference is an error.

This is not an AppGameKit fault - it's (in my opinion) a fault in the language definition of Basic.

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Sep 2013 14:03
yes, but Basic means EASY, not searching hours for a mistyped word.
in visual basic it is just two words at top of a file for the compiler.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 24th Sep 2013 14:22
EASY means obscure bugs as a result of typos. I never have to search for a mistyped word - that's what I have a compiler for!

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Sep 2013 15:24 Edited at: 24th Sep 2013 15:25
emm, if you forget the # in agk it is similar mistyped and there is no compiler error. your "game" did not work expected.
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 24th Sep 2013 15:31
Quote: "This is not an AppGameKit fault - it's (in my opinion) a fault in the language definition of Basic."


I'm not suggesting it's a fault. This is simply a feature suggestion that I think will improve it's credibility for experienced programmers and save people time.

I think to hold the language back using the shortcomings and inadequacies of the original BASIC as an excuse makes about as much sense as not wearing clothes to dinner because cavemen didn't bother.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Sep 2013 15:36
I personally think that if the option was there, 90% of people who tried it would use it all the time.

That in itself would make it worth putting in. Is it in as a feature request on the Google issues list?

Parragil para o mundo!
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 24th Sep 2013 15:57
I agree. I think people very new to programming wouldn't use it but anyone who's ever used a strongly typed language would.

I've not used that issues list before. Just tracked it down. Somebody did submit that as a feature request a couple of years ago and it was accepted. *twiddles thumbs*
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 24th Sep 2013 16:08
This is the Google request. It was accepted by Lee on 9-Jun-2012.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Sep 2013 16:28
my priorities and i believe most of the others are v2.
cu next year
apocolyp4
14
Years of Service
User Offline
Joined: 10th Jun 2010
Location:
Posted: 24th Sep 2013 16:31
As I Python user I've no issue with the current setup. Forcing OPTION EXPLICIT into a language that has never had it will break a lot of users code. Having it as optional would be fine. But I don't think making it compulsory due to lets face it user error is worth break backward compatibility with most if not all current and previous AppGameKit projects.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Sep 2013 17:38 Edited at: 24th Sep 2013 17:39
@apocolyp4
Forcing yes,but still optional
its 100% backward compatibility because you must input this
words by yourself.
in visual basic it was added at a new file if you want this option.
also you had the option to remove it from your source and add it later by hand.
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 24th Sep 2013 20:12
Yes, obviously it should be optional. The clue is in the name 'OPTION EXPLICIT'. If you're new to coding there's enough confusion without defining variables, so it remaining weakly typed by default makes sense. I just think the majority of coders who've used strongly typed languages would benefit.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Sep 2013 00:03
I guess I'm a bit of a lazy coder. I like not having to declare all my variables. And I don't waste much time correcting misspelled names either. And RTA is not exactly a small project.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 25th Sep 2013 00:44
Good luck, DA! I'd rather hear the bad news first!!!!

-- Jim - When is there going to be a release?
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th Sep 2013 01:43
Quote: " ... would complain that fEatenAmount# hadn't been defined. I don't care if fEatenAmount# is defined globally.
"


There's a few catch 22's in all this. Assuming the return type is worked out prior to actual compilation. It's type wouldn't need to be cast by the user even with an explicit mode.

The variables A, B#, c$ and Result in the fragment bellow, would be detected and cast during the initial prototyping pass. The prototypes are needed as the compiler knows the pattern of every function (it's inputs and outputs). So casting the parameters as the parser spots them is actually easier.



another variation is to not create the variables during the prototyping, but during the actual compile. This doesn't really work though, as the prototype pass can't solve the output data type without having a deeper look at the input code. So during the prototyping it has to create the variables (it might already do this, i don't know). So when it reaches the EndFunction statement, the data type of the output term can solved and the function prototype created.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 25th Sep 2013 05:33 Edited at: 25th Sep 2013 05:34
Kevin Picone, I think the issue is more just the use of undefined variables, not of prototyping in function definitions.

Because of the way variables are typed based on the name, that is 'known' and I don't think this thread is concerned about typing related to function return values.

What it is concerned about is using a variable before it is declared. The declaration is either in the function prototype or through a global declaration or just an explicit line like:
thisnum AS Integer
thisflt# AS Float

The idea is that the compiler will help you detect if you've made a typo in a variable in some line because the variable has not been declared. As someone with a formal education in computer programming, and Basic was nowhere near the first language I learned, required variable declaration as a means of avoiding variable typos is something I appreciate.

As others have mentioned, Basic is meant to be easier to work with and that is why it allows creating variables on the fly. But, as others have experienced, this can also make oneself crazy trying to figure out why something doesn't work because we don't see the missing or extra or wrong character in a variable name in one line.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th Sep 2013 07:49
@AL,

Thanks, but I'm pretty familiar with both the problem and the many solutions. The reason for this, is that Explicit was one the first features I added to PlayBASIC over a decade now.

In Fallout's example, fEatenAmount# doesn't need to be declared inside the function, even with an explicit mode enabled. Assuming the prototyper in AppGameKit picks this locals up during the first pass. If so, adding a fEatenAmount as float inside the scope would be completely redundant.



Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 25th Sep 2013 11:12
Well personally I don't mind how it works. If the compiler and/or prototyper looks at what comes after endfunction and declares it for me, that's fine by me. Similarly, if it avoids extra passes or whatever to have the user define a variable type 'fReturn# as float' within the function and then stick it after the endfunction, then that's fine by me too. Whichever works, so long as there is an option to force variable declaration in some form and help me avoid typos.

Strangely last night the problem reared it's head in another way. In my type I have fX# and fXOffset#. I was using fX# instead of fXOffset# by mistake in a particularly complex chain of code. I knew the logic was right, but couldn't fix it. What did I end up doing? Spending maybe 15 minutes looking for typos, as that is usually the problem. So even when you don't have a typo, because you can't rule it out as an issue it still makes life a misery!
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 25th Sep 2013 15:06
Yes, Fallout. Strict typing doesn't solve everything, but as a supermarket chain says, every little helps.

The Delphi IDE is superb in this respect: if I type a variable name that hasn't been declared it will be underlined in red squiggles, so I can fix that without compiling. That - pus code-completion - make it a joy to use.

-- Jim - When is there going to be a release?
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Sep 2013 19:42
Quote: "The Delphi IDE is superb in this respect: if I type a variable name that hasn't been declared it will be underlined in red squiggles, so I can fix that without compiling. That - pus code-completion - make it a joy to use."


Sounds like a nice way of doing it. With a button in the toolbar to instantly turn on and off.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 25th Sep 2013 20:01
Quote: "With a button in the toolbar to instantly turn on and off."


Why would I want to turn it off????

-- Jim - When is there going to be a release?
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Sep 2013 23:52
Quote: "Why would I want to turn it off????"


Because it would be annoying to see it flag all my variables I haven't declared

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 26th Sep 2013 00:08
Try declaring them, and save yourself several hours!

-- Jim - When is there going to be a release?
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 26th Sep 2013 00:26
Quote: "Try declaring them, and save yourself several hours!"


As I've mentioned I don't spend much time checking for misspellings. Yes, they happen. But it doesn't take me long to find them. I do use quite a lot of UDTs and arrays and I use a lot of copy/paste. I only use non declared variables for temp stuff. Would be nice if the editor somehow showed when I have typed in the name of a constant or global, well any kind of declared variable etc. Maybe color code them differently or use bold letters.

nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 7th Oct 2013 12:32
Option Explicit would be extremely useful for me too. After all, OPTION means it can be disabled, thus satisfying people who don't use it.

FreeBasic has Option Explicit (and a lot more).

I have also spent HOURS on variable typo errors and would make full use of this option, should it be introduced.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 7th Oct 2013 14:23
BTW, been using TGC products since DBC and I have never wanted it. But it's a reasonable request, perhaps for the IDE/compiler update in v2?

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Oct 2013 14:36
just a idea,
alternative the compiler can add/insert the declaration
if he need this with a user dialog.
i think its better than "hidden" code.

Login to post a reply

Server time is: 2024-11-24 23:00:59
Your offset time is: 2024-11-24 23:00:59