[Gambas-user] variable declaration everywhere ???

Christof Thalhofer chrisml at deganius.de
Sat Dec 15 14:07:32 CET 2018


Hi Tobi,

my current bed lecture is a German book with the title "Weniger schlecht
Programmieren" which translates to "Less Bad Programming".

Maybe this is why I am so upset concerning the place of variables. As I
switched over from VBA to Gambas the first thing I thought was:

"Declaration only at the top? That's a really cool idea!!11!"

Ok. I think I am too rigid. After reading again, I think what you
mentioned is ok for all who want the rope. But I think I would regulate
the usage of variables in an own coding style inhouse. Yes and I would
like a compiler switch. Especially if I had to read my own code I want
to see the variables at the beginning. And I personally would like to be
forced to do like so.  One of the main reasons for my own bad coding
style was the declaration of variables here and there. I wrote that.

If the question is performance vs readability and performance is crucial
then readability has to suffer.

But here it is not a question of performance. For me it seems to be a
question of comfort for the programmer (or better laziness of the
programmer) vs comfort for the reader. And for me it also seems to be a
question of security. Because code which is shorter and easier to
understand mostly is more secure.

Ok, so ... now as you told me, "I like the compromise that David Sanromá
and Benoît suggested" about variable declaration in loops, I agree to
that, but then sth like that:

> À propos, I think the If and Select Case statements feel left out by
> all the discussion of *loop* variables. Now, how often did you want
> to do
> 
> If (Dim i As Integer = InStr(sStr, sNeedle)) <> 0 Then Mid$(sStr, i,
> 1)... Endif
> 
> I do that all the time in other languages, which support it, and my 
> neck is alright still

... should also be possible.

But what you wrote about "scope", "pollution" and locality of variables
inside a function I think: Variables have to live (r/w) function-wide.
No exception.

Btw: Gosub, Label and Return define inline functions, that's not bad nor
ugly but good for speed.

> PS(A): I missed a good deal of this thread because google decided it> was spam, along with some other mails I've been receiving, and liking>
to receive, for years. If you use gmail, maybe check in and look at>
what you are missing.
I don't like Gmail.

Maybe you should use a provider which respects your privacy and does not
drop mail. In Germany Posteo or mailbox.org seem to be quite good.

Hostsharing is also not bad, but only makes sense if you need (very
good) webspace.


Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181215/aa5e16cc/attachment.sig>


More information about the User mailing list