[Gambas-user] variable declaration everywhere ???
rwe-sse at osnanet.de
Fri Dec 14 11:49:10 CET 2018
Am 14.12.18 um 09:56 schrieb Christof Thalhofer:
> Am 14.12.18 um 00:51 schrieb Benoît Minisini:
>> Or should I remove the possibility of declaring variables anywhere before?
> I would remove that.
I would not. At least not if it has to be explicitly declared with its type.
> Option explicit and the decision to allow the declaration of variables
> only at top in my eyes are the main advantages of Gambas vs VB(A)
> concerning cleaner code.
> Basic seems to be an easy language for beginners, but – as always –
> allows a lot of very ugly code constructions.
That's true - but it's in the programmer's hands.
> Long method bodies for me are a clear sign for bad code.
Mostly it can be - sometimes it's not. But basically I agree.
> As I started programming long ago I did not understand the advantages of
> declaration of variables, and later – as I understood – I declared a lot
> of variables within the body of my methods. As I had to refactor that
> code mess later I found out that I packed a lot of functionality in
> loooong methods which were quite hard to understand.
Was the same in my case.
As I said, I agree, basically, but
> So this decision of Gambas leads to better code!
this CAN have the effect you mention, but it doesn't need to. You still
can produce ugly code, even in Gambas, even without the possibility to
create a variable on the spot.
> I've put a lot of work into a lot of code and the older I get the
> smaller and clearer my methods become. I'm against making it easier for
> programmers to create huge functions full of spaghetti.
If you confine the use of declaring a variable to certain cases, like
loops, it's ok. I wouldn't use it, but others might like it. They will
find out for themselves that their code becomes unmanageable if they use
this too frequently, but it can also become unmanageable through other
(bad) habits. A bad programmer will produce bad code, you cannot keep
him doing from it just by forbidding some kind of variable declaration.
In VB you can declare a variable by just mentioning it within the code.
That can be pretty handy if you need a counting variable on the fly but
it can as well become tedious. Here we are talking about declaring it
with a declaration keyword for the variable type, so a kind of formal
declaration is still needed, and someone reading the code can see "this
variable was declared at this point".
Just my 2 cents...
More information about the User