Re: [Gambas-user] static const?

2010-04-16 Thread Doriano Blengino
Charlie Reinl ha scritto:
 Am Donnerstag, den 15.04.2010, 21:07 +0300 schrieb Jussi Lahtinen:

 Yes, you can test it.

 This should generate error:
 If 1 = 2 And 1 / 0 Then Print test

 This should not.:
 If 1 = 2 And If 1 / 0 Then Print test

  

  if itabstrip1.count and tabstrip1[i].caption=

 can fail, if I understand well. Perhaps I must check a few lines of code...

  
 yes you are right for that example

 (my teacher said never try to divide something by 0).

 And I do not understand why/what/where that condition is/could be
 good for ... 1/0 !?

 but
 If 1 = 1 And 1  2 Then Print test
 and
 If 1 = 1 And If 1  2 Then Print test

 works the same way.

The problem is this. Suppose you have to test a property of a object; if 
the object exists, and its property value is 1 you do something:

 if theobjectNULL and theobject.number=1 THEN ...

The above statement is wrong, because gambas evaluates the second 
expression even if the first is false; doing so, it tries to read a 
property of a non-existent object. I checked the documentation (perhaps 
a little old), and this behavior is not specified. It is true that you 
find an alternative syntax, looking strange at first but nice, like IF 
expr and IF otherexpr THEN ..., but this does say nothing about the 
classic syntax.

Coming from years of programming in C and pascal, I gave for normal that 
short-circuit is common practice, but this is not the case. So I must 
check a few lines of code.

Better explanation can be found on wikipedia: 
http://en.wikipedia.org/wiki/Short-circuit_evaluation

Ciao,
Doriano


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-16 Thread Jussi Lahtinen
 (my teacher said never try to divide something by 0).

 And I do not understand why/what/where that condition is/could be
 good for ... 1/0 !?

 Dividing by zero is guaranteed error. That is exactly reason why I used it to
 test if Gambas has short-circuits or not.
 This is for test purpose only, not for real useful code.


 but
 If 1 = 1 And 1  2 Then Print test
 and
 If 1 = 1 And If 1  2 Then Print test

 This doesn't test for short-circuits, because both of them will print test.
 No indication.


My code;
If 1 = 2 And If 1 / 0 Then Print test
does not create error IF language is short-circuit capable,
because execute of statement will stop at 1 = 2.

Jussi

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-15 Thread Doriano Blengino
Fabián Flores Vadell ha scritto:
 2010/4/14 Doriano Blengino doriano.bleng...@fastwebnet.it:
   

 First example. I store some bookmarks...
 ...

 I could break out the loop using a logic variable, but this way I save a
 variable. Or I could test the variable in the loop construct, like this:
 
 I don't agree the criteria for saving one variable or one expresion if
 it is not justified.
   
Well, perhaps my daily work with little CPUs (some have 32 bytes of 
ram!) drives me to professional bias, but why use a variable if can be 
avoided? There is more than one reason for this (reported without an 
order). One: variables have to be declared at the beginning of a block; 
when I write code, if I want to use a variable I must go back to the 
start of the code and add the declaration, leaving the old road of my 
mind. Then I must go back to the relevant part and concentrate again on 
the code. Two: saving a state to later break a loop is less 
straightforward than doing it in place. If the logic of an algorithm 
is concentrated in a single point, instead of being spread around, it 
is easier to revise - at least for me. Three: I think that fast 
algorithms are always better than slow ones. It is the duty of a good 
programmer to write good code: and good code is fast and easy to read. 
Perhaps, if I was a teacher, I would say different things. But teachers 
sometimes are a little distant from the reality; and scholars will face 
it later - when they will be programmers. Speed *is* important, the 
battle on computer hardware and software is all around performances. 
That said, using a variable is a cost (even more for interpreted 
languages like gambas). Well - we must understand each other. By no mean 
I want to say that using variables is awful - is a technique with pros 
and cons.


 Now, image an hypothetical case in that you have to do several
 conditional actions inside the loop. If you resolves it in that way,
 the code become hard to understand.

 Catch the joke:

   FOR tries = 1 TO 2' to search again from the top
 DO
   IF Upper(Left(ME.item.Text, i)) = searchstring THEN
 ' found item
 RETURN
   ENDIF
   IF ME.MoveBelow() THEN BREAK
   IF (YOU DONT LIKE) THEN RETURN
   IF (YOU WANT) THEN RETURN
   IF (NOT ME ..). THEN BREAK
   IF (YOU DONT...) THEN BREAK
   IF (YOU WRITE IN C) THEN RETURN
   ...
 LOOP
 ME.MoveFirst
   NEXT

 Ok, I know you wouldn't write something like that. Just I want to
 serve to show what I mean.
   
Ah ah ah! You are wrong... this is my preferred style. I actually 
*write* things like that, especially when conditions are related. I mean 
- suppose you want to test the caption of a tabstrip (oh! what a 
coincidence...). You must read Tabstrip[i].Caption, but first you have 
to make sure that Tabstrip[i] really exists. So the test becomes:

if (iTabStrip.count) and (tabstrip[i].caption blahblahblah) THEN 
blahblahblah

This is a logical mislead, because it puts together two unrelated 
concepts: the test on the relevant thing (we look for caption), and a 
good precaution which has little to do with the algorithm. In fact, I 
would rewrite it as

if itabstrip.count then if tabstrip[i].caption...

There is no difference in the final (machine) code, but the second 
statement looks to me more explanatory. And, to be sincere, there is 
more. The ambiguity of the first statement is well stressed in other 
languages (sorry, they exist), where sometimes there is no warranty 
about the order of evaluation of expressions. For whatever reason, a 
compiler could evaluate tabstrip[i].caption *before* tabstrip.count. 
And, of course, the compiler is right - the AND operation is commutative 
(the two terms can be swapped), like addition and multiplication. Back 
to gambas - I don't know if the documentation says anything about 
short-circuit and things like that. May be we can assume it as a 
standard, that modern languages always do short-circuit, but the concept 
remains. This is why in many cases I could write, especially in a cycle:

if i=tabstrip.count then break
if tabstrip[i].caption ... then ...

Here, the focus about the counter i, and the usage of .caption is 
even more separated - two statements instead of one - because they are 
at two different levels. This is only an example I stretched beyond the 
reality, but you got it.

 If you have to do tests (like unit tests) and you have routines with
 multiple exit points, maybe you will have some coverage problems. What
 do you think?
   
I think that it is exactly the same thing. If you use a variable to 
break a loop, or return from a function, then that variable is an exit 
point. With an additional problem - that the variable can be changed 
later... a RETURN is always a RETURN instead.
At this point, I would add that single return points are, for me, 
worse than multiple exit point. Excuse me again if I pull in other 
languages, but now they are 

Re: [Gambas-user] static const?

2010-04-15 Thread Jussi Lahtinen
 Back to gambas - I don't know if the documentation says anything about
 short-circuit and things like that. May be we can assume it as a
 standard, that modern languages always do short-circuit, but the concept
 remains.

 Gambas doesn't have short-circuits, you have to write like this:
 IF a=1 AND IF b=2 THEN

Jussi

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-15 Thread Doriano Blengino
Jussi Lahtinen ha scritto:
 Back to gambas - I don't know if the documentation says anything about
 short-circuit and things like that. May be we can assume it as a
 standard, that modern languages always do short-circuit, but the concept
 remains.
 

  Gambas doesn't have short-circuits, you have to write like this:
  IF a=1 AND IF b=2 THEN

   
Ah! Thanks. So, a statement like this:

if itabstrip1.count and tabstrip1[i].caption=

can fail, if I understand well. Perhaps I must check a few lines of code...

Regards,
Doriano

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-15 Thread Charlie Reinl
Am Donnerstag, den 15.04.2010, 19:28 +0200 schrieb Doriano Blengino:
 Jussi Lahtinen ha scritto:
  Back to gambas - I don't know if the documentation says anything about
  short-circuit and things like that. May be we can assume it as a
  standard, that modern languages always do short-circuit, but the concept
  remains.
  
 
   Gambas doesn't have short-circuits, you have to write like this:
   IF a=1 AND IF b=2 THEN
 

 Ah! Thanks. So, a statement like this:
 
 if itabstrip1.count and tabstrip1[i].caption=
 
 can fail, if I understand well. Perhaps I must check a few lines of code...
 
 Regards,
 Doriano

Salut,

I'v never done it like that (IF a=1 AND IF b=2 THEN), are you sure ? 
-- 
Amicalement
Charlie


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-15 Thread Jussi Lahtinen
Yes, you can test it.

This should generate error:
If 1 = 2 And 1 / 0 Then Print test

This should not.:
If 1 = 2 And If 1 / 0 Then Print test

Jussi


On Thu, Apr 15, 2010 at 20:56, Charlie Reinl karl.re...@fen-net.de wrote:
 Am Donnerstag, den 15.04.2010, 19:28 +0200 schrieb Doriano Blengino:
 Jussi Lahtinen ha scritto:
  Back to gambas - I don't know if the documentation says anything about
  short-circuit and things like that. May be we can assume it as a
  standard, that modern languages always do short-circuit, but the concept
  remains.
 
 
   Gambas doesn't have short-circuits, you have to write like this:
   IF a=1 AND IF b=2 THEN
 
 
 Ah! Thanks. So, a statement like this:

     if itabstrip1.count and tabstrip1[i].caption=

 can fail, if I understand well. Perhaps I must check a few lines of code...

 Regards,
 Doriano

 Salut,

 I'v never done it like that (IF a=1 AND IF b=2 THEN), are you sure ?
 --
 Amicalement
 Charlie


 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-15 Thread Les Hardy
Charlie Reinl wrote:
 Am Donnerstag, den 15.04.2010, 19:28 +0200 schrieb Doriano Blengino:
   
 Jussi Lahtinen ha scritto:
 
 Back to gambas - I don't know if the documentation says anything about
 short-circuit and things like that. May be we can assume it as a
 standard, that modern languages always do short-circuit, but the concept
 remains.
 
 
  Gambas doesn't have short-circuits, you have to write like this:
  IF a=1 AND IF b=2 THEN

   
   
 Ah! Thanks. So, a statement like this:

 if itabstrip1.count and tabstrip1[i].caption=

 can fail, if I understand well. Perhaps I must check a few lines of code...

 Regards,
 Doriano
 

 Salut,

 I'v never done it like that (IF a=1 AND IF b=2 THEN), are you sure ? 
   
Yes, It is clearly there in the manual.

*IF* _Expression_ [ { *AND IF* | *OR IF* } _Expression_ ... ] [ *THEN* ]
  ...
[ *ELSE IF* _Expression_ [ { *AND IF* | *OR IF* } _Expression_ ... ] [ *THEN* ]
  ... ]
[ *ELSE*
  ... ]
*ENDIF*



--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-15 Thread Fabián Flores Vadell
 I don't agree the criteria for saving one variable or one expresion if
 it is not justified.

 Well, perhaps my daily work with little CPUs (some have 32 bytes of
 ram!) drives me to professional bias, but why use a variable if can be
 avoided? There is more than one reason for this (reported without an
 order). One: variables have to be declared at the beginning of a block;
 when I write code, if I want to use a variable I must go back to the
 start of the code and add the declaration, leaving the old road of my
 mind. Then I must go back to the relevant part and concentrate again on
 the code.

I don't see the problem here. When you think about create a variable
(or any other memory structure), you never let to think about your
algorithm. In fact, if the language require previous variable
declaration is a good thing because forces to think about on
resources you will use and how you will do that.

I think that the choices about memory structures is one of the
critical parts when you write an algorithm.

So, when you think about variables far away of divert attention,
actually you are deepening your understanding about the problem and
your algorithmic solution.

 Two: saving a state to later break a loop is less
 straightforward than doing it in place. If the logic of an algorithm
 is concentrated in a single point, instead of being spread around, it
 is easier to revise - at least for me.

 Three: I think that fast
 algorithms are always better than slow ones.

I think that if the speed is a requeriment, that's right. But if not,
just is right if is to easy to do. So, not always a faster algorithm
is better. Let me quote to Donald Knuth when he said premature
optimization is the root of all evil (or at least most of it) in
programming.

 It is the duty of a good
 programmer to write good code: and good code is fast and easy to read.

I believe that a good code is one that is simple, and to achieve this
goal at least must (sure I forget something):

- Uses the correct structures of memory and control
- Have high cohesion and low coupling
- Be correctly modularized
- Uses good names
- Be written in order that it is easy to understand it

 Perhaps, if I was a teacher, I would say different things. But teachers
 sometimes are a little distant from the reality; and scholars will face
 it later - when they will be programmers.

The industry insists in that the most important things are compliance
of requirements and easy maintenance.

 That said, using a variable is a cost (even more for interpreted
 languages like gambas). Well - we must understand each other. By no mean
 I want to say that using variables is awful - is a technique with pros
 and cons.

Easy, I understand you.

    if (iTabStrip.count) and (tabstrip[i].caption blahblahblah) THEN
 blahblahblah

 This is a logical mislead, because it puts together two unrelated
 concepts: the test on the relevant thing (we look for caption), and a
 good precaution which has little to do with the algorithm. In fact, I
 would rewrite it as

    if itabstrip.count then if tabstrip[i].caption...

 There is no difference in the final (machine) code, but the second
 statement looks to me more explanatory.

I agree.

 And, to be sincere, there is
 more. The ambiguity of the first statement is well stressed in other
 languages (sorry, they exist), where sometimes there is no warranty
 about the order of evaluation of expressions. For whatever reason, a
 compiler could evaluate tabstrip[i].caption *before* tabstrip.count.
 And, of course, the compiler is right - the AND operation is commutative
 (the two terms can be swapped), like addition and multiplication. Back
 to gambas - I don't know if the documentation says anything about
 short-circuit and things like that. May be we can assume it as a
 standard, that modern languages always do short-circuit, but the concept
 remains.

I agree.

  function movefile(src, dst as string) as boolean
    result = false
    if not exists(src) then return
    if not open_and_read(src) then return
    close(src)
    if not open_and_write(dst) then return
    close(dst)
    result = true
  end

 Now comes personal taste. The second routine, for you, is a joke.

Oh, no. The joke was: IF (YouWriteInC) THEN RETURN. Maybe, we not
share the same humor sense.

 For
 me, it looks simpler, shorter, and faster. The only problem I see are
 those repeated not and return. They are ugly to see, but very clear
 in saying if this operation fails, then stop. The code coverage should
 be simpler to do, but I am not really sure.

When I have to write many logical tests, I separates them in a new
function. That allow me keep the code short and self explanatory. I do
this in a extremist way especially when I want to anybody can
understand my code.

I know this is even more expensive than using a variable. I don't
care, I never seen a penalization over performance for that, and if I
have to do some optimization, I would do later.

 I think that the 

Re: [Gambas-user] static const?

2010-04-15 Thread Charlie Reinl
Am Donnerstag, den 15.04.2010, 21:07 +0300 schrieb Jussi Lahtinen:
 Yes, you can test it.
 
 This should generate error:
 If 1 = 2 And 1 / 0 Then Print test
 
 This should not.:
 If 1 = 2 And If 1 / 0 Then Print test
 
 Jussi
 
 
 On Thu, Apr 15, 2010 at 20:56, Charlie Reinl karl.re...@fen-net.de wrote:
  Am Donnerstag, den 15.04.2010, 19:28 +0200 schrieb Doriano Blengino:
  Jussi Lahtinen ha scritto:
   Back to gambas - I don't know if the documentation says anything about
   short-circuit and things like that. May be we can assume it as a
   standard, that modern languages always do short-circuit, but the concept
   remains.
  
  
Gambas doesn't have short-circuits, you have to write like this:
IF a=1 AND IF b=2 THEN
  
  
  Ah! Thanks. So, a statement like this:
 
  if itabstrip1.count and tabstrip1[i].caption=
 
  can fail, if I understand well. Perhaps I must check a few lines of code...
 
  Regards,
  Doriano
 
  Salut,
 
  I'v never done it like that (IF a=1 AND IF b=2 THEN), are you sure ?
  --
  Amicalement
  Charlie
 

Salut,

yes you are right for that example 

(my teacher said never try to divide something by 0).

And I do not understand why/what/where that condition is/could be
good for ... 1/0 !?

but 
If 1 = 1 And 1  2 Then Print test
and
If 1 = 1 And If 1  2 Then Print test

works the same way.
-- 
Amicalement
Charlie


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Doriano Blengino
Fabián Flores Vadell ha scritto:
 2010/4/13 Jussi Lahtinenjussi.lahti...@gmail.com:

 Just in case:

 REPEAT
  b = TabStrip3.Count ' In fact, this does nothing usefull
  INC a
 UNTIL a  TabStrip3.Count OR TabStrip3[a].Caption = IdCaption

   This doesn't make same functionality.
  
I can't resist to add my mis-contribute...

Back to the beginning: a CONST declaration is something that uses no 
memory, so it can not have instances, and hence it can not be STATIC. 
The C language, in facts, does not even have CONSTs - it goes with 
#define. So, it would be correct to forbid STATIC when declaring CONSTs. 
On the other hand, a CONST is always static, because the effective data 
it describes reside in a memory outside the program - they reside in the 
compiler memory.

About the cycles WHILE, FOR, REPEAT and so on, I think the statements 
BREAK and CONTINUE are very useful (I would add a third statement: 
RESTART): they permit a finer control and many times they are clearer 
than complex tests. . Your example only has two test, against COUNT and 
the CAPTION. What kind of test would you write if the conditions were 
15? Perhaps concatenated (I mean, some test are only meaningful when 
other conditions are met).

Finally, your last lines of code do not work:
 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte = 0

WHILE (a  TabStrip1.Count - 1) AND (TabStrip1[a].Text  IdCaption)
  INC a
WEND

RETURN IF(TabStrip1[a].Caption = IdCaption, a, -1)
 END

Suppose you have a tabstrip with three tabs, and last, Tabstrip1[2] has 
the caption we want.
In the first cycle, we test Tabstrip1[0]: does not match, and a turns 1
In the secon cycle, we test tabstrip1[1]: does not match and a turns 2
The third cycle does not get executed - a is 2, which is not less than 
3-1 (it is equal).

Moreover, your algorithm does a double test on caption, which could be 
avoided. Doing an additional test is not an important thing if the test 
is quick and the routine is called not too much often. What if the 
routine is called millions time, or the test is more heavy?

About not using RETURN or BREAK inside cycles, we must think at 
different kind of cycles. The WHILE and alike, where no variables are 
directly involved in the cycle declaration, never have problems - the 
semantic of the declaration does not imply anything about variable 
allocation. In the FOR cycles instead, other languages can do strange 
things, both on allocation and code optimization, so it is effectively a 
bad idea to fiddle with the loop control variable; in other languages 
this is not stressed the same way (basic, for example), but actually is, 
at least, ugly.

It seems to me that you have said that an exception would be the FOR 
EACH cycle... why?

Regards,
Doriano


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Les Hardy


 The C language, in facts, does not even have CONSTs - it goes with 
 #define. So, it would be correct to forbid STATIC when declaring CONSTs.
Surely this is not correct. ANSI C uses const, and C++ also uses the 
const keyword.
#define (a preprocessor directive) is a relic from old C, and const is 
now recommended use instead.

Also, it would be correct to use static with const, the line below would 
be correct use.

static const int daysPerMonth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};


Having said that, The original question was not about C,  I think Fabian 
was simply asking about the scope of constants in classes (in Gambas)


Regards
Les Hardy

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Doriano Blengino
Les Hardy ha scritto:

 The C language, in facts, does not even have CONSTs - it goes with
 #define. So, it would be correct to forbid STATIC when declaring CONSTs.
  
 Surely this is not correct. ANSI C uses const, and C++ also uses the
 const keyword.
 #define (a preprocessor directive) is a relic from old C, and const is
 now recommended use instead.

Surely, according to http://www.ericgiguere.com/articles/ansi-c-summary.html
 The declaration:
  enum colours { RED, BLUE, GREEN };


 would declare colours as an enumeration tag representing the integer 
 constants RED, BLUE and GREEN. These enumeration constants are given 
 integer values starting at 0 and increasing by 1 with each identifier.

 An enumeration constant may be used wherever an integer is expected. 
 The following is equivalent to the above enumerated type:

  #define RED   0
  #define BLUE  1
  #define GREEN 2


Moreover, from http://tigcc.ticalc.org/doc/keywords.html


 _const_

 *Makes variable value or pointer parameter unmodifiable.*

 When |const| is used with a variable, it uses the following syntax:

 const/variable-name/  [ =/value/];


 In this case, the |const| modifier allows you to assign an initial 
 value to a variable that cannot later be changed by the program. For 
 example,

 const my_age = 32;


 Any assignments to |'my_age'| will result in a compiler error. 
 However, such declaration is quite different than using

 #define my_age 32

 In the first case, the compiler allocates a memory for |'my_age'| and 
 stores the initial value 32 there, but it will not allow any later 
 assignment to this variable. But, in the second case, all occurences 
 of |'my_age'| are simply replaced with 32 by the preprocessor 
 http://tigcc.ticalc.org/doc/cpp.html, and no memory will be 
 allocated for it.

You perhaps refer to const modifier, which is different from declaring 
a constant, like in
 public:
 WinEDA_VertexCtrl( wxWindow* parent, const wxString title,
wxBoxSizer* BoxSizer, int units, int 
 internal_unit );

 Also, it would be correct to use static with const, the line below would
 be correct use.

 static const int daysPerMonth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

In this case - talking about C and not C++:
 |static| tells that a function or data element is only known within 
 the scope of the current compile. In addition, if you use the |static| 
 keyword with a variable that is local to a function, it allows the 
 last value of the variable to be preserved between successive calls to 
 that function. 
const says that data is not modifiable, so static would say the same 
thing. Note also the ambiguity of the keyword when applied to data 
global to a module, and data local to a function - the same keyword does 
two very different things.


 Having said that, The original question was not about C,  I think Fabian
 was simply asking about the scope of constants in classes (in Gambas)

Uhm... is it forbidden to cite other languages to better explain a 
concept? So why you cited C++?

Anyway, you are right, the original question was about scope. In gambas 
scope is governed by PRIVATE and PUBLIC. Full stop.

If you feel that my reply is a little hurting, excuse me; it is because 
your reply seemed hurting to me. Prove to me that I am wrong and I will 
publicly apologize.

Regards,
Doriano

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Fabián Flores Vadell
2010/4/14 Doriano Blengino doriano.bleng...@fastwebnet.it:

 Back to the beginning: a CONST declaration is something that uses no
 memory, so it can not have instances, and hence it can not be STATIC.

 On the other hand, a CONST is always static, because the effective data
 it describes reside in a memory outside the program - they reside in the
 compiler memory.

Thanks Doriano. I understand that. My question was caused by the fact
that the compiler allows use the keyword STATIC in the declaration of
constants, even though the online help and a very basic logical
reasoning indicate that use the keyword STATIC is unnecesary in this
situation

 About the cycles WHILE, FOR, REPEAT and so on, I think the statements
 BREAK and CONTINUE are very useful (I would add a third statement:
 RESTART): they permit a finer control and many times they are clearer
 than complex tests.

You do not give arguments to support your opinion. Can you give me
some examples? I think, that these can be obvious for you, but not for
me.

 Your example only has two test, against COUNT and
 the CAPTION. What kind of test would you write if the conditions were
 15? Perhaps concatenated (I mean, some test are only meaningful when
 other conditions are met).

Assign the results of logical expressions to Boolean variables, it is
often the way to manage the complexity of conditionals expressions.
And in the loops, to use these variables instead of those logical
expressions.

But I think that you are knowing well this, and you points to the
performance of programs. If so, my answer is that the performance
isn't a priority in many types of programs, and the evaluation of
logical expressions have a little cost in comparation with other
operations (I/O, compression, among many others).

 Finally, your last lines of code do not work:

Yes, it works.

 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte = 0

    WHILE (a  TabStrip1.Count - 1) AND (TabStrip1[a].Text  IdCaption)
      INC a
    WEND

    RETURN IF(TabStrip1[a].Caption = IdCaption, a, -1)
 END

 The third cycle does not get executed - a is 2, which is not less than
 3-1 (it is equal).

That's irrelevant because the external comprobation (the logical
expression in the return sentence)

 Moreover, your algorithm does a double test on caption, which could be
 avoided.

I think that the second test can't to be avoided. If it isn't put out
the loop, you have to put into the loop. The reason for include the
test (TabStrip1[a].Text  IdCaption) in conditional expression is
only stop the loop if there's match before get the last item.

I think that this code can to write in many ways, but with no
significant variations. How would you do?

 Doing an additional test is not an important thing if the test
 is quick and the routine is called not too much often. What if the
 routine is called millions time, or the test is more heavy?

I think that the computational cost of evaluate complex logical
expressions, generally is insignificant. But if not, then the first
thing to be considerated is the language to use, and I see few
alternatives: assembler, C, C++, someone else; the second thing is the
many optimizations to do. But, what kind the system would be? One that
is not possible to do with Gambas.

 About not using RETURN or BREAK inside cycles, we must think at
 different kind of cycles. The WHILE and alike, where no variables are
 directly involved in the cycle declaration, never have problems - the
 semantic of the declaration does not imply anything about variable
 allocation. In the FOR cycles instead, other languages can do strange
 things, both on allocation and code optimization, so it is effectively a
 bad idea to fiddle with the loop control variable; in other languages
 this is not stressed the same way (basic, for example), but actually is,
 at least, ugly.

Yep, but I not was thinking in possible collateral effects, derived
from implementation of language. (To those, the corresponding compiler
would let in evidence, or would become a logical error isn't very
difficult to detect and correct). I was thinking in conceptuals
implications.

This conceptuals implications derives in to use of the language
resources in any ways, instead to use them in the correct situations.

 It seems to me that you have said that an exception would be the FOR
 EACH cycle... why?

FOR EACH really iterates through all items, so there's only way to
stop the loop when it's goal is achieved, is by the BREAK sentence
used in a conditonal sentence inside the loop. But it might think that
if it is necessary to do this, then the iterative structure FOR EACH
is not adequate.

And I hope that my very ugly english, does not cause tears.

-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, 

Re: [Gambas-user] static const?

2010-04-14 Thread Les Hardy

If you feel hurt I am sorry for that, it was not my intention to hurt 
you, and I have no wish to prove you wrong.
I do still stand by my statement.

Regards
Les Hardy



Doriano Blengino wrote:
 Les Hardy ha scritto:
   

 
 The C language, in facts, does not even have CONSTs - it goes with
 #define. So, it would be correct to forbid STATIC when declaring CONSTs.
  
   
 Surely this is not correct. ANSI C uses const, and C++ also uses the
 const keyword.
 #define (a preprocessor directive) is a relic from old C, and const is
 now recommended use instead.

 
 Surely, according to http://www.ericgiguere.com/articles/ansi-c-summary.html
   
 The declaration:
  enum colours { RED, BLUE, GREEN };


 would declare colours as an enumeration tag representing the integer 
 constants RED, BLUE and GREEN. These enumeration constants are given 
 integer values starting at 0 and increasing by 1 with each identifier.

 An enumeration constant may be used wherever an integer is expected. 
 The following is equivalent to the above enumerated type:

  #define RED   0
  #define BLUE  1
  #define GREEN 2

 

 Moreover, from http://tigcc.ticalc.org/doc/keywords.html
   
 _const_

 *Makes variable value or pointer parameter unmodifiable.*

 When |const| is used with a variable, it uses the following syntax:

 const/variable-name/  [ =/value/];


 In this case, the |const| modifier allows you to assign an initial 
 value to a variable that cannot later be changed by the program. For 
 example,

 const my_age = 32;


 Any assignments to |'my_age'| will result in a compiler error. 
 However, such declaration is quite different than using

 #define my_age 32

 In the first case, the compiler allocates a memory for |'my_age'| and 
 stores the initial value 32 there, but it will not allow any later 
 assignment to this variable. But, in the second case, all occurences 
 of |'my_age'| are simply replaced with 32 by the preprocessor 
 http://tigcc.ticalc.org/doc/cpp.html, and no memory will be 
 allocated for it.
 

 You perhaps refer to const modifier, which is different from declaring 
 a constant, like in
   
 public:
 WinEDA_VertexCtrl( wxWindow* parent, const wxString title,
wxBoxSizer* BoxSizer, int units, int 
 internal_unit );
 

   
 Also, it would be correct to use static with const, the line below would
 be correct use.

 static const int daysPerMonth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

 
 In this case - talking about C and not C++:
   
 |static| tells that a function or data element is only known within 
 the scope of the current compile. In addition, if you use the |static| 
 keyword with a variable that is local to a function, it allows the 
 last value of the variable to be preserved between successive calls to 
 that function. 
 
 const says that data is not modifiable, so static would say the same 
 thing. Note also the ambiguity of the keyword when applied to data 
 global to a module, and data local to a function - the same keyword does 
 two very different things.

   
 Having said that, The original question was not about C,  I think Fabian
 was simply asking about the scope of constants in classes (in Gambas)

 
 Uhm... is it forbidden to cite other languages to better explain a 
 concept? So why you cited C++?

 Anyway, you are right, the original question was about scope. In gambas 
 scope is governed by PRIVATE and PUBLIC. Full stop.

 If you feel that my reply is a little hurting, excuse me; it is because 
 your reply seemed hurting to me. Prove to me that I am wrong and I will 
 publicly apologize.

 Regards,
 Doriano

   


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Doriano Blengino
Fabián Flores Vadell ha scritto:
 2010/4/14 Doriano Blenginodoriano.bleng...@fastwebnet.it:


 Back to the beginning: a CONST declaration is something that uses no
 memory, so it can not have instances, and hence it can not be STATIC.
  
 Thanks Doriano. I understand that. My question was caused by the fact
 that the compiler allows use the keyword STATIC in the declaration of
 constants, even though the online help and a very basic logical
 reasoning indicate that use the keyword STATIC is unnecesary in this
 situation

And here we return on your idea about a good compiler - and it is mine 
idea too. A good compiler should be very precise about things that have 
sense, and can be done, and things that can not be done, or have no meaning.
In this respect, it is a nonsense to let the user write a CONST 
STATIC. But compilers sometimes must keep compatibility with other, 
older, compilers. So, in this case, may be that VB(tm) was accepting 
this, and so does gambas. But I don't know VB(tm). Anyway, this issue is 
harmless, so I don't see it as a big problem.

 About the cycles WHILE, FOR, REPEAT and so on, I think the statements
 BREAK and CONTINUE are very useful (I would add a third statement:
 RESTART): they permit a finer control and many times they are clearer
 than complex tests.
  
 You do not give arguments to support your opinion. Can you give me
 some examples? I think, that these can be obvious for you, but not for
 me.

First of all, I must say that I see your point. May be that all the 
issue is about personal style. But I did a quick research in my sources 
to let you see some example. I have little code in gambas - I use a lot 
C, about which I could have many examples but, as stated by someone 
other, it is forbidden to talk about C...

First example. I store some bookmarks in a file by using the Settings 
class. Every bookmark is stored with a name like Bmark1, Bmark2 and 
so on, but I don't know how many of them are in the file. I know when 
there are no more values, instead. So the routine is the following:

   i = 1
   DO
 st = settings[Bmark  i, ]
 IF st =  THEN BREAK
 men = NEW Menu(mnBooks) AS chgBook
 men.Caption = st
 INC i
   LOOP

Now, to understand if there are more bookmarks to read, I must try to 
read it. If the value is NULL, then the job is finished. Clearly, a 
FOR-NEXT is no good (or, one can write a for-next from 1 to 1000... 
misleading...).
I could break out the loop using a logic variable, but this way I save a 
variable. Or I could test the variable in the loop construct, like this:

   i = 1
   DO
 st = settings[Bmark  i, ]
 if st then
   men = NEW Menu(mnBooks) AS chgBook
   men.Caption = st
 ENDIF
 INC i
   while st

but, as you see, there are TWO tests instead of one, and there is an 
added line of code. May be that I am missing something, but the BREAK 
instruction is really useful here.

The second example is a textual search on a treeview. If the user types 
some text, the selection is moved on the next item beginning with that 
text. If no more items satisfy the criterium, the search must start 
again at the top, but only once. So the code (there is a ME.MoveBelow() 
just before this code, I omitted it for simplicity):

   i = Len(searchstring)
   FOR tries = 1 TO 2' to search again from the top
 DO
   IF Upper(Left(ME.item.Text, i)) = searchstring THEN
 ' found item
 RETURN
   ENDIF
   IF ME.MoveBelow() THEN BREAK
 LOOP
 ME.MoveFirst
   NEXT

Here, the FOR-NEXT is a quick way to execute some code for no more than 
two times...
Again, I could have used a variable to store the result of the test, but 
I saved it...
And again this is not, perhaps, the best code you can see around - but 
it works, and it is reasonably fast and short.



 Your example only has two test, against COUNT and
 the CAPTION. What kind of test would you write if the conditions were
 15? Perhaps concatenated (I mean, some test are only meaningful when
 other conditions are met).
  
 Assign the results of logical expressions to Boolean variables, it is
 often the way to manage the complexity of conditionals expressions.
 And in the loops, to use these variables instead of those logical
 expressions.

 But I think that you are knowing well this, and you points to the
 performance of programs. If so, my answer is that the performance
 isn't a priority in many types of programs, and the evaluation of
 logical expressions have a little cost in comparation with other
 operations (I/O, compression, among many others).

I agree, and partly not.
I think that clearness and beatiful code is to prefer against speed, but 
only when speed is not an issue.
In the text-search example speed *is* an issue. Never tried to open a 
directory with some 3 files in it, and perform a textual search? KDE 
solves elegantly... it does textual search *only* if the sort order is 
by name. 

Re: [Gambas-user] static const?

2010-04-14 Thread Doriano Blengino
Errata corrige:

 
 Finally, your last lines of code do not work:
  
   
 Yes, it works.


 
 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte = 0

 WHILE (aTabStrip1.Count - 1) AND (TabStrip1[a].Text
 IdCaption)
   INC a
 WEND

 RETURN IF(TabStrip1[a].Caption = IdCaption, a, -1)
 END

 

 
 The third cycle does not get executed - a is 2, which is not less than
 3-1 (it is equal).
  
   
 That's irrelevant because the external comprobation (the logical
 expression in the return sentence)

 
 May be that I am missing something, but... how can you say that it works 
 if it omits to test the last item?
   
Time later, driving to home and still thinking about this routine, I 
finally recalled what you wanted to say with comprobation.
Yes, you are right - your code works. If I would have payed more 
attention to the routine, I would have noticed. But, stupidly, I 
concentrated only on the cycle, noting that it was missing a test on the 
last item. That last item is managed by the last test before exiting.

Still I don't like this routine. What happens if TabStrip1.Count=0 
(emtpy tabstrip)?

Ok, now I'am home, it's late - so good night to everybody (in Europe, of 
course).

Regards,

-- 
Doriano Blengino

Listen twice before you speak.
This is why we have two ears, but only one mouth.


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-14 Thread Fabián Flores Vadell
2010/4/14 Doriano Blengino doriano.bleng...@fastwebnet.it:
 And here we return on your idea about a good compiler - and it is mine
 idea too.

I don't want judge if the Gambas compiler is good or not, I feel that
I don't have the knowledge or experience required for do that. But, I
shared with you about the taste for a compiler that to say at
programmer: This is right. That's not a good idea.

 First of all, I must say that I see your point. May be that all the
 issue is about personal style.
Yes, I have to admit that the style surely have influence in the
beauty criteria.

 But I did a quick research in my sources
 to let you see some example. I have little code in gambas - I use a lot
 C, about which I could have many examples but, as stated by someone
 other, it is forbidden to talk about C...

Ha! Is forbidden if you want that I can understand you. That is true :)

 First example. I store some bookmarks in a file by using the Settings
 class. Every bookmark is stored with a name like Bmark1, Bmark2 and
 so on, but I don't know how many of them are in the file. I know when
 there are no more values, instead. So the routine is the following:

   i = 1
   DO
     st = settings[Bmark  i, ]
     IF st =  THEN BREAK
     men = NEW Menu(mnBooks) AS chgBook
     men.Caption = st
     INC i
   LOOP
 ...

 I could break out the loop using a logic variable, but this way I save a
 variable. Or I could test the variable in the loop construct, like this:

 ...


 but, as you see, there are TWO tests instead of one, and there is an
 added line of code.

I don't agree the criteria for saving one variable or one expresion if
it is not justified.

 May be that I am missing something, but the BREAK
 instruction is really useful here.

I don't say that BREAK (and other sentences) haven't utility, but that
isn't strictly necessary (perhaps I said unnecesary and this word may
be incorrect).

 The second example is a textual search on a treeview. If the user types
 some text, the selection is moved on the next item beginning with that
 text. If no more items satisfy the criterium, the search must start
 again at the top, but only once. So the code (there is a ME.MoveBelow()
 just before this code, I omitted it for simplicity):

   i = Len(searchstring)
   FOR tries = 1 TO 2    ' to search again from the top
     DO
       IF Upper(Left(ME.item.Text, i)) = searchstring THEN
         ' found item
         RETURN
       ENDIF
       IF ME.MoveBelow() THEN BREAK
     LOOP
     ME.MoveFirst
   NEXT

 Here, the FOR-NEXT is a quick way to execute some code for no more than
 two times...
 Again, I could have used a variable to store the result of the test, but
 I saved it...

I think that you use a structure FOR-NEXT that requires to you knowing
the amount of iterations to do. But, in this case you know that is
likely the number of iterations declared could be unnecesary. So,
conceptually, the correct loop would be one that allow control the
number of iterations.

There isn't a practical problem here. Just a conceptual consideration.
This doesn't matter if you understand what you do, like in you case.
But I think that's important for who is learning to programming. (I'm
sorry, I'm a teacher -and may be some day I have to teach
programming-). However, I don't want keep with older patterns of
thought. So, will I keep open my mind.

Now, image an hypothetical case in that you have to do several
conditional actions inside the loop. If you resolves it in that way,
the code become hard to understand.

Catch the joke:

  FOR tries = 1 TO 2' to search again from the top
DO
  IF Upper(Left(ME.item.Text, i)) = searchstring THEN
' found item
RETURN
  ENDIF
  IF ME.MoveBelow() THEN BREAK
  IF (YOU DONT LIKE) THEN RETURN
  IF (YOU WANT) THEN RETURN
  IF (NOT ME ..). THEN BREAK
  IF (YOU DONT...) THEN BREAK
  IF (YOU WRITE IN C) THEN RETURN
  ...
LOOP
ME.MoveFirst
  NEXT

Ok, I know you wouldn't write something like that. Just I want to
serve to show what I mean.

 I think that clearness and beatiful code is to prefer against speed, but
 only when speed is not an issue.

I agree.

 In the text-search example speed *is* an issue. Never tried to open a
 directory with some 3 files in it, and perform a textual search?

Ok, I agree.

 I would do so:

 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte = 0

   WHILE a  TabStrip1.Count
      if TabStrip1[a].Text = IdCaption then return a
     INC a
   WEND
   return -1
 END

 PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
 DIM a AS Byte

   for a = 0 to TabStrip1.Count-1
      if TabStrip1[a].Text = IdCaption then return a
   next
   return -1
 END

If you have to do tests (like unit tests) and you have routines with
multiple exit points, maybe you will have some coverage problems. What
do you think?

 No, the issue is different. Giving any language and any cpu, every
 operation has a cost. Comparing two 

Re: [Gambas-user] static const?

2010-04-14 Thread Fabián Flores Vadell
2010/4/14 Doriano Blengino doriano.bleng...@fastwebnet.it:
 Errata corrige:

 May be that I am missing something, but... how can you say that it works
 if it omits to test the last item?


 Time later, driving to home and still thinking about this routine, I
 finally recalled what you wanted to say with comprobation.
 Yes, you are right - your code works. If I would have payed more
 attention to the routine, I would have noticed. But, stupidly, I
 concentrated only on the cycle, noting that it was missing a test on the
 last item. That last item is managed by the last test before exiting.

 Still I don't like this routine. What happens if TabStrip1.Count=0
 (emtpy tabstrip)?

Ouch! TabStrip without tabs doesn't fit in my mind, ie Why somebody
want a TabStrip without at least one tab?

Moreover, by default TabStrip have one tab. (design time and execution time).

 Listen twice before you speak.
 This is why we have two ears, but only one mouth.

ha! Very funny. I like it.

Regards.

-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] static const?

2010-04-13 Thread Fabián Flores Vadell
Hi everybody.

Well, all us knows that a constant is something that can't change.
Then, constants would be class members. So, when a class is
instantiated, constants should be shared by all instances.

The online help exclude the use of STATIC keyword in the declaration
of constants, so the STATIC keyword would be innecesary. Is this
really the case or is it necessary to declare the constants by the
STATIC keyword? (STATIC [PUBLIC | PRIVATE] CONST)

-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Benoît Minisini
 Hi everybody.
 
 Well, all us knows that a constant is something that can't change.
 Then, constants would be class members. So, when a class is
 instantiated, constants should be shared by all instances.
 
 The online help exclude the use of STATIC keyword in the declaration
 of constants, so the STATIC keyword would be innecesary. Is this
 really the case or is it necessary to declare the constants by the
 STATIC keyword? (STATIC [PUBLIC | PRIVATE] CONST)

No STATIC with CONST. Or maybe the compiler is more tolerant than that?

-- 
Benoît Minisini

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Fabián Flores Vadell
 No STATIC with CONST. Or maybe the compiler is more tolerant than that?

Maybe the compiler is a too much good guy :)

I think that the compiler shouldn't allow to do something like that:


PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer

  DIM a AS Integer = 0
  DIM b AS Integer = 0

  FOR a = 1 TO TabStrip3.Count STEP 1
      IF TabStrip3[(a - 1)].Caption = IdCaption THEN
         b = a
         a = TabStrip3.Count
         RETURN a
      ENDIF
  NEXT

END


Someone thought that this code is good one.

Leaving aside the obvious conceptual confusion of the author, and that
the routine doesn't do what it claims, it is important to note that it
is possible to change the variable that controls the FOR structure,
and included the return statement inside the loop.

I think the compiler should not allow these things, at least for mercy
through the eyes of those who are finally forced to read code like
this.


-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Benoît Minisini
  No STATIC with CONST. Or maybe the compiler is more tolerant than that?
 
 Maybe the compiler is a too much good guy :)
 
 I think that the compiler shouldn't allow to do something like that:
 
 
 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
 
   DIM a AS Integer = 0
   DIM b AS Integer = 0
 
   FOR a = 1 TO TabStrip3.Count STEP 1
   IF TabStrip3[(a - 1)].Caption = IdCaption THEN
  b = a
  a = TabStrip3.Count
  RETURN a
   ENDIF
   NEXT
 
 END
 
 
 Someone thought that this code is good one.
 
 Leaving aside the obvious conceptual confusion of the author, and that
 the routine doesn't do what it claims, it is important to note that it
 is possible to change the variable that controls the FOR structure,
 and included the return statement inside the loop.
 
 I think the compiler should not allow these things, at least for mercy
 through the eyes of those who are finally forced to read code like
 this.

Why shouldn't the compiler allow to modify a loop variable? It is sometimes 
useful.

Why shouldn't the compiler allow to return from inside a loop? It is perfectly 
valid to do that.

A bad programmer using some syntax for writing bad code does not necessary 
imply that that syntax should be forbidden.

Regards,

-- 
Benoît Minisini

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Jussi Lahtinen
Generally bad code...
What that supposed to do?
Either it will return TabStrip3.Count or zero.

This would do exactly same thing:

PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer

  FOR a = 0 TO TabStrip3.Count - 1
  IF TabStrip3[a].Caption = IdCaption THEN
 RETURN TabStrip3.Count
  ENDIF
  NEXT

END

Jussi


2010/4/13 Fabián Flores Vadell fabianfloresvad...@gmail.com:
 No STATIC with CONST. Or maybe the compiler is more tolerant than that?

 Maybe the compiler is a too much good guy :)

 I think that the compiler shouldn't allow to do something like that:


 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer

   DIM a AS Integer = 0
   DIM b AS Integer = 0

   FOR a = 1 TO TabStrip3.Count STEP 1
       IF TabStrip3[(a - 1)].Caption = IdCaption THEN
          b = a
          a = TabStrip3.Count
          RETURN a
       ENDIF
   NEXT

 END


 Someone thought that this code is good one.

 Leaving aside the obvious conceptual confusion of the author, and that
 the routine doesn't do what it claims, it is important to note that it
 is possible to change the variable that controls the FOR structure,
 and included the return statement inside the loop.

 I think the compiler should not allow these things, at least for mercy
 through the eyes of those who are finally forced to read code like
 this.


 --
 Fabián Flores Vadell
 www.speedbooksargentina.blogspot.com

 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Jussi Lahtinen
I forgot Dim a as integer but you got the point.

Jussi


On Tue, Apr 13, 2010 at 22:29, Jussi Lahtinen jussi.lahti...@gmail.com wrote:
 Generally bad code...
 What that supposed to do?
 Either it will return TabStrip3.Count or zero.

 This would do exactly same thing:

 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer

  FOR a = 0 TO TabStrip3.Count - 1
      IF TabStrip3[a].Caption = IdCaption THEN
         RETURN TabStrip3.Count
      ENDIF
  NEXT

 END

 Jussi


 2010/4/13 Fabián Flores Vadell fabianfloresvad...@gmail.com:
 No STATIC with CONST. Or maybe the compiler is more tolerant than that?

 Maybe the compiler is a too much good guy :)

 I think that the compiler shouldn't allow to do something like that:


 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer

   DIM a AS Integer = 0
   DIM b AS Integer = 0

   FOR a = 1 TO TabStrip3.Count STEP 1
       IF TabStrip3[(a - 1)].Caption = IdCaption THEN
          b = a
          a = TabStrip3.Count
          RETURN a
       ENDIF
   NEXT

 END


 Someone thought that this code is good one.

 Leaving aside the obvious conceptual confusion of the author, and that
 the routine doesn't do what it claims, it is important to note that it
 is possible to change the variable that controls the FOR structure,
 and included the return statement inside the loop.

 I think the compiler should not allow these things, at least for mercy
 through the eyes of those who are finally forced to read code like
 this.


 --
 Fabián Flores Vadell
 www.speedbooksargentina.blogspot.com

 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user



--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Fabián Flores Vadell
 Why shouldn't the compiler allow to modify a loop variable? It is sometimes
 useful.

I'm refering to the loop FOR only. IMHO, WHILE and REPEAT are good
structures that allow at programmer take absolute control over
iterations, objective of FOR is iterate all items of a memory
structure. At least, I think that was of the original design purpose
(distorted after).

In fact, the need of FOR structure is relative. Any need can be easily
cover with WHILE and REPEAT.

I don't see the need for break a iteration structure from inside, in
any way (even break and continue). This would be done from conditional
input or output of the structure. But I see the consecuences.

May be, the exeption to this is FOR EACH structure.

 Why shouldn't the compiler allow to return from inside a loop? It is perfectly
 valid to do that.

Why allow break a loop in this way? That often leads to write multiple
statements  RETURN in a function. That does not comply with the
theorem of structured programming (that have as one of its premises
allow only a input point and unique exit). I think that in practice
this difficults the tests; if necesary to port the code, this could be
an aditional problem; among other things.

 A bad programmer using some syntax for writing bad code does not necessary
 imply that that syntax should be forbidden.

I agree, but actually I was thinking that this affect more to those
who approach programming in an informal way.


-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Fabián Flores Vadell
2010/4/13 Jussi Lahtinen jussi.lahti...@gmail.com:
 I forgot Dim a as integer but you got the point.

 Jussi

Yes Jussi. But my point isn't to do that the code work, it's show a
bad use of language resources.

-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Jussi Lahtinen
First you referred to FOR loop only,
but with case of return command you are talking more generally about loops?
Or so I understand as you are speaking about it's influence to code structure.

Consider this, if you have VERY long iteration and but you are done
with first element of iteration.
Then there is no reason to continue iteration anymore, because it is
just waste of time.

Let's take your example (I did clean it up):

PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
Dim a as Integer

 FOR a = 0 TO TabStrip3.Count - 1
 IF TabStrip3[a].Caption = IdCaption THEN
RETURN TabStrip3.Count
 ENDIF
 NEXT

RETURN 0
END

Now this is not very realistic case with this example, but let's
pretend it is so.
Let's say that this iteration takes 10 second to run trough and there
are 10 items.
When first item is what is needed, then this function takes only 1
second to execute.
If we do not break that loop it will always take 10 seconds.

Just to make sure, you meant it should be like this?

PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
Dim a as Integer
Dim b as Integer

 FOR a = 0 TO TabStrip3.Count - 1
 IF TabStrip3[a].Caption = IdCaption THEN
b = TabStrip3.Count
 ENDIF
 NEXT

RETURN b
END


Also you should notice, that this is normal practice in Basic languages.
And therefore also question of portability.

Jussi



2010/4/14 Fabián Flores Vadell fabianfloresvad...@gmail.com:
 Why shouldn't the compiler allow to modify a loop variable? It is sometimes
 useful.

 I'm refering to the loop FOR only. IMHO, WHILE and REPEAT are good
 structures that allow at programmer take absolute control over
 iterations, objective of FOR is iterate all items of a memory
 structure. At least, I think that was of the original design purpose
 (distorted after).

 In fact, the need of FOR structure is relative. Any need can be easily
 cover with WHILE and REPEAT.

 I don't see the need for break a iteration structure from inside, in
 any way (even break and continue). This would be done from conditional
 input or output of the structure. But I see the consecuences.

 May be, the exeption to this is FOR EACH structure.

 Why shouldn't the compiler allow to return from inside a loop? It is 
 perfectly
 valid to do that.

 Why allow break a loop in this way? That often leads to write multiple
 statements  RETURN in a function. That does not comply with the
 theorem of structured programming (that have as one of its premises
 allow only a input point and unique exit). I think that in practice
 this difficults the tests; if necesary to port the code, this could be
 an aditional problem; among other things.

 A bad programmer using some syntax for writing bad code does not necessary
 imply that that syntax should be forbidden.

 I agree, but actually I was thinking that this affect more to those
 who approach programming in an informal way.


 --
 Fabián Flores Vadell
 www.speedbooksargentina.blogspot.com

 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Jussi Lahtinen
Aaa I think you meant it this way:

PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
Dim a as Integer
Dim b as Integer

REPEAT
   IF TabStrip3[a].Caption = IdCaption THEN
  b = TabStrip3.Count
  BREAK
   ENDIF
WHILE a  TabStrip3.Count

RETURN b
END

Jussi


On Wed, Apr 14, 2010 at 01:55, Jussi Lahtinen jussi.lahti...@gmail.com wrote:
 First you referred to FOR loop only,
 but with case of return command you are talking more generally about loops?
 Or so I understand as you are speaking about it's influence to code structure.

 Consider this, if you have VERY long iteration and but you are done
 with first element of iteration.
 Then there is no reason to continue iteration anymore, because it is
 just waste of time.

 Let's take your example (I did clean it up):

 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
 Dim a as Integer

  FOR a = 0 TO TabStrip3.Count - 1
     IF TabStrip3[a].Caption = IdCaption THEN
        RETURN TabStrip3.Count
     ENDIF
  NEXT

 RETURN 0
 END

 Now this is not very realistic case with this example, but let's
 pretend it is so.
 Let's say that this iteration takes 10 second to run trough and there
 are 10 items.
 When first item is what is needed, then this function takes only 1
 second to execute.
 If we do not break that loop it will always take 10 seconds.

 Just to make sure, you meant it should be like this?

 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
 Dim a as Integer
 Dim b as Integer

  FOR a = 0 TO TabStrip3.Count - 1
     IF TabStrip3[a].Caption = IdCaption THEN
        b = TabStrip3.Count
     ENDIF
  NEXT

 RETURN b
 END


 Also you should notice, that this is normal practice in Basic languages.
 And therefore also question of portability.

 Jussi



 2010/4/14 Fabián Flores Vadell fabianfloresvad...@gmail.com:
 Why shouldn't the compiler allow to modify a loop variable? It is sometimes
 useful.

 I'm refering to the loop FOR only. IMHO, WHILE and REPEAT are good
 structures that allow at programmer take absolute control over
 iterations, objective of FOR is iterate all items of a memory
 structure. At least, I think that was of the original design purpose
 (distorted after).

 In fact, the need of FOR structure is relative. Any need can be easily
 cover with WHILE and REPEAT.

 I don't see the need for break a iteration structure from inside, in
 any way (even break and continue). This would be done from conditional
 input or output of the structure. But I see the consecuences.

 May be, the exeption to this is FOR EACH structure.

 Why shouldn't the compiler allow to return from inside a loop? It is 
 perfectly
 valid to do that.

 Why allow break a loop in this way? That often leads to write multiple
 statements  RETURN in a function. That does not comply with the
 theorem of structured programming (that have as one of its premises
 allow only a input point and unique exit). I think that in practice
 this difficults the tests; if necesary to port the code, this could be
 an aditional problem; among other things.

 A bad programmer using some syntax for writing bad code does not necessary
 imply that that syntax should be forbidden.

 I agree, but actually I was thinking that this affect more to those
 who approach programming in an informal way.


 --
 Fabián Flores Vadell
 www.speedbooksargentina.blogspot.com

 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user



--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Jussi Lahtinen
Always forgetting something... INC a.

Jussi


On Wed, Apr 14, 2010 at 01:59, Jussi Lahtinen jussi.lahti...@gmail.com wrote:
 Aaa I think you meant it this way:

 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
 Dim a as Integer
 Dim b as Integer

 REPEAT
   IF TabStrip3[a].Caption = IdCaption THEN
      b = TabStrip3.Count
      BREAK
   ENDIF
 WHILE a  TabStrip3.Count

 RETURN b
 END

 Jussi


 On Wed, Apr 14, 2010 at 01:55, Jussi Lahtinen jussi.lahti...@gmail.com 
 wrote:
 First you referred to FOR loop only,
 but with case of return command you are talking more generally about loops?
 Or so I understand as you are speaking about it's influence to code 
 structure.

 Consider this, if you have VERY long iteration and but you are done
 with first element of iteration.
 Then there is no reason to continue iteration anymore, because it is
 just waste of time.

 Let's take your example (I did clean it up):

 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
 Dim a as Integer

  FOR a = 0 TO TabStrip3.Count - 1
     IF TabStrip3[a].Caption = IdCaption THEN
        RETURN TabStrip3.Count
     ENDIF
  NEXT

 RETURN 0
 END

 Now this is not very realistic case with this example, but let's
 pretend it is so.
 Let's say that this iteration takes 10 second to run trough and there
 are 10 items.
 When first item is what is needed, then this function takes only 1
 second to execute.
 If we do not break that loop it will always take 10 seconds.

 Just to make sure, you meant it should be like this?

 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
 Dim a as Integer
 Dim b as Integer

  FOR a = 0 TO TabStrip3.Count - 1
     IF TabStrip3[a].Caption = IdCaption THEN
        b = TabStrip3.Count
     ENDIF
  NEXT

 RETURN b
 END


 Also you should notice, that this is normal practice in Basic languages.
 And therefore also question of portability.

 Jussi



 2010/4/14 Fabián Flores Vadell fabianfloresvad...@gmail.com:
 Why shouldn't the compiler allow to modify a loop variable? It is sometimes
 useful.

 I'm refering to the loop FOR only. IMHO, WHILE and REPEAT are good
 structures that allow at programmer take absolute control over
 iterations, objective of FOR is iterate all items of a memory
 structure. At least, I think that was of the original design purpose
 (distorted after).

 In fact, the need of FOR structure is relative. Any need can be easily
 cover with WHILE and REPEAT.

 I don't see the need for break a iteration structure from inside, in
 any way (even break and continue). This would be done from conditional
 input or output of the structure. But I see the consecuences.

 May be, the exeption to this is FOR EACH structure.

 Why shouldn't the compiler allow to return from inside a loop? It is 
 perfectly
 valid to do that.

 Why allow break a loop in this way? That often leads to write multiple
 statements  RETURN in a function. That does not comply with the
 theorem of structured programming (that have as one of its premises
 allow only a input point and unique exit). I think that in practice
 this difficults the tests; if necesary to port the code, this could be
 an aditional problem; among other things.

 A bad programmer using some syntax for writing bad code does not necessary
 imply that that syntax should be forbidden.

 I agree, but actually I was thinking that this affect more to those
 who approach programming in an informal way.


 --
 Fabián Flores Vadell
 www.speedbooksargentina.blogspot.com

 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user




--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Fabián Flores Vadell
2010/4/13 Jussi Lahtinen jussi.lahti...@gmail.com:
 Aaa I think you meant it this way:

 PUBLIC FUNCTION ScanTab(IdCaption AS Integer) AS Integer
 Dim a as Integer
 Dim b as Integer

 REPEAT
   IF TabStrip3[a].Caption = IdCaption THEN
      b = TabStrip3.Count
      BREAK
   ENDIF
 WHILE a  TabStrip3.Count

 RETURN b
 END

 Jussi

You're getting close. But, I think that is no need to break the loop
using the BREAK sentence. Just you must find the right condition to
the loop.

I don't refer to that example anymore, because is easier explain it in
a more abstract level:

REPEAT
   'do something
UNTIL cond1 OR (cond2 AND cond3) ...

WHILE cond1 AND cond2 OR cond3
  'do something
WEND

Where one of the above conditions (condX) is that usually is write
inside the loop to allow the BREAK or CONTINUE sentence (or RETURN).

Just in case:

REPEAT
 b = TabStrip3.Count ' In fact, this does nothing usefull
 INC a
UNTIL a  TabStrip3.Count OR TabStrip3[a].Caption = IdCaption


-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Jussi Lahtinen
 Just in case:

 REPEAT
     b = TabStrip3.Count ' In fact, this does nothing usefull
     INC a
 UNTIL a  TabStrip3.Count OR TabStrip3[a].Caption = IdCaption

 This doesn't make same functionality.
 Because if ldCaption doesn't match to any of tabstrip captions,
 function will still answer TabStrip3.Count instead of zero.
 In short, you cannot remove IF THEN construct.

 I think I have done enough errors for this day (I'm going to sleep).

Jussi

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] static const?

2010-04-13 Thread Fabián Flores Vadell
2010/4/13 Jussi Lahtinen jussi.lahti...@gmail.com:
 Just in case:

 REPEAT
     b = TabStrip3.Count ' In fact, this does nothing usefull
     INC a
 UNTIL a  TabStrip3.Count OR TabStrip3[a].Caption = IdCaption

  This doesn't make same functionality.

That is why I did not want to follow the example anymore.

This function never had has any functionality, due to their errors.
Neither, your version of the function, because it returns
TabStrip3.Count which is the amount of tabs containing the control, ie
always return the same value.

  Because if ldCaption doesn't match to any of tabstrip captions,
  function will still answer TabStrip3.Count instead of zero.
  In short, you cannot remove IF THEN construct.

Put it out of loop.


The correct code:


PRIVATE FUNCTION ScanTab(IdCaption AS String) AS Byte
DIM a AS Byte = 0

  WHILE (a  TabStrip1.Count - 1) AND (TabStrip1[a].Text  IdCaption)
INC a
  WEND

  RETURN IF(TabStrip1[a].Caption = IdCaption, a, -1)
END

  I think I have done enough errors for this day (I'm going to sleep).

Sweet dreams (my childs are going to sleep right now, too).


-- 
Fabián Flores Vadell
www.speedbooksargentina.blogspot.com

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user