Csound Csound-dev Csound-tekno Search About

[Cs-dev] (buggy?) variable initialization with if-then

Date2013-05-01 11:46
FromBen Hackbarth
Subject[Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
hello!

in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.

am i missing something?

thanks!
--  ben


<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 32
nchnls = 2
0dbfs  = 1


instr 1
    iBool = 1
    if (iBool == 0) then
        iTest = 20
    else
        iOther = 10
    endif
    print iTest
endin


</CsInstruments>
<CsScore>
i 1   0   1
e
</CsScore>
</CsoundSynthesizer>

Date2013-05-01 12:30
FromVictor Lazzarini
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
 The variable is not initialised at any point. The code iTest = 0 (assignment at i-time, not initialisation), just does not run if iBool is 0. The
variable just holds whatever garbage it contains. 

You can see this by running the following code:



-n


sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iBool = p4
if (iBool == 0) then
iTest = 20
else
iOther = 10
endif
print iTest
endin




i 1 0 1 0
i 1 1 1 1
e



It will be set to 20 in the first run of instr 1, and then will keep this value in the second, since it's reusing the memory space of the
first run (as only one allocation is needed).

Victor
On 1 May 2013, at 11:46, Ben Hackbarth wrote:

> hello!
> 
> in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.
> 
> am i missing something?
> 
> thanks!
> --  ben
> 
> 
> 
> 
> -n
> 
> 
> sr     = 44100
> ksmps  = 32
> nchnls = 2
> 0dbfs  = 1
> 
> 
> instr 1
>     iBool = 1
>     if (iBool == 0) then
>         iTest = 20
>     else
>         iOther = 10
>     endif
>     print iTest
> endin
> 
> 
> 
> 
> i 1   0   1
> e
> 
> 
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2013-05-01 12:39
FromBen Hackbarth
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
i see.  is this seen as a feature of csound coding?  if not, why not throw an error similar to those thrown when a user asks for a variable that does not exist?

it seems to me only a point of confusion.  in my experience it makes programming/debugging lots of if-then blocks difficult as one might have variables of the same name in different conditional blocks and then accidentally use previously stored values.  at least, i am running into those kinds of problems at the moment.

--  ben


On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
 The variable is not initialised at any point. The code iTest = 0 (assignment at i-time, not initialisation), just does not run if iBool is 0. The
variable just holds whatever garbage it contains.

You can see this by running the following code:

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iBool = p4
if (iBool == 0) then
iTest = 20
else
iOther = 10
endif
print iTest
endin


</CsInstruments>
<CsScore>
i 1 0 1 0
i 1 1 1 1
e
</CsScore>
</CsoundSynthesizer>

It will be set to 20 in the first run of instr 1, and then will keep this value in the second, since it's reusing the memory space of the
first run (as only one allocation is needed).

Victor
On 1 May 2013, at 11:46, Ben Hackbarth wrote:

> hello!
>
> in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.
>
> am i missing something?
>
> thanks!
> --  ben
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
> <CsInstruments>
> sr     = 44100
> ksmps  = 32
> nchnls = 2
> 0dbfs  = 1
>
>
> instr 1
>     iBool = 1
>     if (iBool == 0) then
>         iTest = 20
>     else
>         iOther = 10
>     endif
>     print iTest
> endin
>
>
> </CsInstruments>
> <CsScore>
> i 1   0   1
> e
> </CsScore>
> </CsoundSynthesizer>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


Date2013-05-01 13:09
FromVictor Lazzarini
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
I guess there are two issues here, one that is kind of semantic/syntactical and the other to do with backward compatibility.

The first thing is that the parser will not know in all cases whether a variable is set or not. It will only know if a constant is used (as in your case).
There is no way currently to tell at run time whether a variable has been set or not, before we use it (as far as I know at least).

Secondly, if we implement something that will change this behaviour, we might break existing code and that is a no-go zone.
(This is my opinion, of course. I might be wrong about it breaking existing code)

Victor
On 1 May 2013, at 12:39, Ben Hackbarth wrote:

i see.  is this seen as a feature of csound coding?  if not, why not throw an error similar to those thrown when a user asks for a variable that does not exist?

it seems to me only a point of confusion.  in my experience it makes programming/debugging lots of if-then blocks difficult as one might have variables of the same name in different conditional blocks and then accidentally use previously stored values.  at least, i am running into those kinds of problems at the moment.

--  ben


On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
 The variable is not initialised at any point. The code iTest = 0 (assignment at i-time, not initialisation), just does not run if iBool is 0. The
variable just holds whatever garbage it contains.

You can see this by running the following code:

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iBool = p4
if (iBool == 0) then
iTest = 20
else
iOther = 10
endif
print iTest
endin


</CsInstruments>
<CsScore>
i 1 0 1 0
i 1 1 1 1
e
</CsScore>
</CsoundSynthesizer>

It will be set to 20 in the first run of instr 1, and then will keep this value in the second, since it's reusing the memory space of the
first run (as only one allocation is needed).

Victor
On 1 May 2013, at 11:46, Ben Hackbarth wrote:

> hello!
>
> in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.
>
> am i missing something?
>
> thanks!
> --  ben
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
> <CsInstruments>
> sr     = 44100
> ksmps  = 32
> nchnls = 2
> 0dbfs  = 1
>
>
> instr 1
>     iBool = 1
>     if (iBool == 0) then
>         iTest = 20
>     else
>         iOther = 10
>     endif
>     print iTest
> endin
>
>
> </CsInstruments>
> <CsScore>
> i 1   0   1
> e
> </CsScore>
> </CsoundSynthesizer>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




Date2013-05-01 13:33
FromVictor Lazzarini
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
Note that this is the case in other languages as well. In C:

#include <stdio.h>
int main(){
  int a, b, c;
  scanf("%d", &a);
  if(a) b = 10;
  else c = 0;
  printf("%d\n", c);
  return 0;
}

the compiler will not tell you that c can be used uninitialized, even if you compile this with -Wuninitialized. 



Victor
On 1 May 2013, at 13:09, Victor Lazzarini wrote:

I guess there are two issues here, one that is kind of semantic/syntactical and the other to do with backward compatibility.

The first thing is that the parser will not know in all cases whether a variable is set or not. It will only know if a constant is used (as in your case).
There is no way currently to tell at run time whether a variable has been set or not, before we use it (as far as I know at least).

Secondly, if we implement something that will change this behaviour, we might break existing code and that is a no-go zone.
(This is my opinion, of course. I might be wrong about it breaking existing code)

Victor
On 1 May 2013, at 12:39, Ben Hackbarth wrote:

i see.  is this seen as a feature of csound coding?  if not, why not throw an error similar to those thrown when a user asks for a variable that does not exist?

it seems to me only a point of confusion.  in my experience it makes programming/debugging lots of if-then blocks difficult as one might have variables of the same name in different conditional blocks and then accidentally use previously stored values.  at least, i am running into those kinds of problems at the moment.

--  ben


On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
 The variable is not initialised at any point. The code iTest = 0 (assignment at i-time, not initialisation), just does not run if iBool is 0. The
variable just holds whatever garbage it contains.

You can see this by running the following code:

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iBool = p4
if (iBool == 0) then
iTest = 20
else
iOther = 10
endif
print iTest
endin


</CsInstruments>
<CsScore>
i 1 0 1 0
i 1 1 1 1
e
</CsScore>
</CsoundSynthesizer>

It will be set to 20 in the first run of instr 1, and then will keep this value in the second, since it's reusing the memory space of the
first run (as only one allocation is needed).

Victor
On 1 May 2013, at 11:46, Ben Hackbarth wrote:

> hello!
>
> in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.
>
> am i missing something?
>
> thanks!
> --  ben
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
> <CsInstruments>
> sr     = 44100
> ksmps  = 32
> nchnls = 2
> 0dbfs  = 1
>
>
> instr 1
>     iBool = 1
>     if (iBool == 0) then
>         iTest = 20
>     else
>         iOther = 10
>     endif
>     print iTest
> endin
>
>
> </CsInstruments>
> <CsScore>
> i 1   0   1
> e
> </CsScore>
> </CsoundSynthesizer>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




Date2013-05-01 13:39
FromVictor Lazzarini
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
In performance, however, both branches seem to be initialised, but it still does not reveal the bug.

On 1 May 2013, at 13:33, Victor Lazzarini wrote:

Note that this is the case in other languages as well. In C:

#include <stdio.h>
int main(){
  int a, b, c;
  scanf("%d", &a);
  if(a) b = 10;
  else c = 0;
  printf("%d\n", c);
  return 0;
}

the compiler will not tell you that c can be used uninitialized, even if you compile this with -Wuninitialized. 



Victor
On 1 May 2013, at 13:09, Victor Lazzarini wrote:

I guess there are two issues here, one that is kind of semantic/syntactical and the other to do with backward compatibility.

The first thing is that the parser will not know in all cases whether a variable is set or not. It will only know if a constant is used (as in your case).
There is no way currently to tell at run time whether a variable has been set or not, before we use it (as far as I know at least).

Secondly, if we implement something that will change this behaviour, we might break existing code and that is a no-go zone.
(This is my opinion, of course. I might be wrong about it breaking existing code)

Victor
On 1 May 2013, at 12:39, Ben Hackbarth wrote:

i see.  is this seen as a feature of csound coding?  if not, why not throw an error similar to those thrown when a user asks for a variable that does not exist?

it seems to me only a point of confusion.  in my experience it makes programming/debugging lots of if-then blocks difficult as one might have variables of the same name in different conditional blocks and then accidentally use previously stored values.  at least, i am running into those kinds of problems at the moment.

--  ben


On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
 The variable is not initialised at any point. The code iTest = 0 (assignment at i-time, not initialisation), just does not run if iBool is 0. The
variable just holds whatever garbage it contains.

You can see this by running the following code:

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iBool = p4
if (iBool == 0) then
iTest = 20
else
iOther = 10
endif
print iTest
endin


</CsInstruments>
<CsScore>
i 1 0 1 0
i 1 1 1 1
e
</CsScore>
</CsoundSynthesizer>

It will be set to 20 in the first run of instr 1, and then will keep this value in the second, since it's reusing the memory space of the
first run (as only one allocation is needed).

Victor
On 1 May 2013, at 11:46, Ben Hackbarth wrote:

> hello!
>
> in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.
>
> am i missing something?
>
> thanks!
> --  ben
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
> <CsInstruments>
> sr     = 44100
> ksmps  = 32
> nchnls = 2
> 0dbfs  = 1
>
>
> instr 1
>     iBool = 1
>     if (iBool == 0) then
>         iTest = 20
>     else
>         iOther = 10
>     endif
>     print iTest
> endin
>
>
> </CsInstruments>
> <CsScore>
> i 1   0   1
> e
> </CsScore>
> </CsoundSynthesizer>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




Date2013-05-01 21:23
FromBen Hackbarth
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
agreed, but there are other languages where this is not the case, like in python:

b=1
if b == 0:
    test=0
print test

... in which case python throws a NameError.  

since, afaik, you cannot create variables in csound without also assigning their value (unlike C), i had assumed that asking for a variable that was not explicitly inited should result in an error.  i did not think that retrieving garbage was even possible.

but i'm not really a programmer, so if this does not seem suspect to yall, its ok by me.  however, it would be helpful if this was documented somehow.

thanks victor.




--  ben


On Wed, May 1, 2013 at 2:39 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
In performance, however, both branches seem to be initialised, but it still does not reveal the bug.

On 1 May 2013, at 13:33, Victor Lazzarini wrote:

Note that this is the case in other languages as well. In C:

#include <stdio.h>
int main(){
  int a, b, c;
  scanf("%d", &a);
  if(a) b = 10;
  else c = 0;
  printf("%d\n", c);
  return 0;
}

the compiler will not tell you that c can be used uninitialized, even if you compile this with -Wuninitialized. 



Victor
On 1 May 2013, at 13:09, Victor Lazzarini wrote:

I guess there are two issues here, one that is kind of semantic/syntactical and the other to do with backward compatibility.

The first thing is that the parser will not know in all cases whether a variable is set or not. It will only know if a constant is used (as in your case).
There is no way currently to tell at run time whether a variable has been set or not, before we use it (as far as I know at least).

Secondly, if we implement something that will change this behaviour, we might break existing code and that is a no-go zone.
(This is my opinion, of course. I might be wrong about it breaking existing code)

Victor
On 1 May 2013, at 12:39, Ben Hackbarth wrote:

i see.  is this seen as a feature of csound coding?  if not, why not throw an error similar to those thrown when a user asks for a variable that does not exist?

it seems to me only a point of confusion.  in my experience it makes programming/debugging lots of if-then blocks difficult as one might have variables of the same name in different conditional blocks and then accidentally use previously stored values.  at least, i am running into those kinds of problems at the moment.

--  ben


On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
 The variable is not initialised at any point. The code iTest = 0 (assignment at i-time, not initialisation), just does not run if iBool is 0. The
variable just holds whatever garbage it contains.

You can see this by running the following code:

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iBool = p4
if (iBool == 0) then
iTest = 20
else
iOther = 10
endif
print iTest
endin


</CsInstruments>
<CsScore>
i 1 0 1 0
i 1 1 1 1
e
</CsScore>
</CsoundSynthesizer>

It will be set to 20 in the first run of instr 1, and then will keep this value in the second, since it's reusing the memory space of the
first run (as only one allocation is needed).

Victor
On 1 May 2013, at 11:46, Ben Hackbarth wrote:

> hello!
>
> in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.
>
> am i missing something?
>
> thanks!
> --  ben
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
> <CsInstruments>
> sr     = 44100
> ksmps  = 32
> nchnls = 2
> 0dbfs  = 1
>
>
> instr 1
>     iBool = 1
>     if (iBool == 0) then
>         iTest = 20
>     else
>         iOther = 10
>     endif
>     print iTest
> endin
>
>
> </CsInstruments>
> <CsScore>
> i 1   0   1
> e
> </CsScore>
> </CsoundSynthesizer>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel



Date2013-05-01 21:41
FromVictor Lazzarini
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
That is because of the interpreted nature of Python. Csound does not work like that, because the compilation and run times are separate.
On 1 May 2013, at 21:23, Ben Hackbarth wrote:

agreed, but there are other languages where this is not the case, like in python:

b=1
if b == 0:
    test=0
print test

... in which case python throws a NameError.  

since, afaik, you cannot create variables in csound without also assigning their value (unlike C), i had assumed that asking for a variable that was not explicitly inited should result in an error.  i did not think that retrieving garbage was even possible.

but i'm not really a programmer, so if this does not seem suspect to yall, its ok by me.  however, it would be helpful if this was documented somehow.

thanks victor.




--  ben


On Wed, May 1, 2013 at 2:39 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
In performance, however, both branches seem to be initialised, but it still does not reveal the bug.

On 1 May 2013, at 13:33, Victor Lazzarini wrote:

Note that this is the case in other languages as well. In C:

#include <stdio.h>
int main(){
  int a, b, c;
  scanf("%d", &a);
  if(a) b = 10;
  else c = 0;
  printf("%d\n", c);
  return 0;
}

the compiler will not tell you that c can be used uninitialized, even if you compile this with -Wuninitialized. 



Victor
On 1 May 2013, at 13:09, Victor Lazzarini wrote:

I guess there are two issues here, one that is kind of semantic/syntactical and the other to do with backward compatibility.

The first thing is that the parser will not know in all cases whether a variable is set or not. It will only know if a constant is used (as in your case).
There is no way currently to tell at run time whether a variable has been set or not, before we use it (as far as I know at least).

Secondly, if we implement something that will change this behaviour, we might break existing code and that is a no-go zone.
(This is my opinion, of course. I might be wrong about it breaking existing code)

Victor
On 1 May 2013, at 12:39, Ben Hackbarth wrote:

i see.  is this seen as a feature of csound coding?  if not, why not throw an error similar to those thrown when a user asks for a variable that does not exist?

it seems to me only a point of confusion.  in my experience it makes programming/debugging lots of if-then blocks difficult as one might have variables of the same name in different conditional blocks and then accidentally use previously stored values.  at least, i am running into those kinds of problems at the moment.

--  ben


On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
 The variable is not initialised at any point. The code iTest = 0 (assignment at i-time, not initialisation), just does not run if iBool is 0. The
variable just holds whatever garbage it contains.

You can see this by running the following code:

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iBool = p4
if (iBool == 0) then
iTest = 20
else
iOther = 10
endif
print iTest
endin


</CsInstruments>
<CsScore>
i 1 0 1 0
i 1 1 1 1
e
</CsScore>
</CsoundSynthesizer>

It will be set to 20 in the first run of instr 1, and then will keep this value in the second, since it's reusing the memory space of the
first run (as only one allocation is needed).

Victor
On 1 May 2013, at 11:46, Ben Hackbarth wrote:

> hello!
>
> in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.
>
> am i missing something?
>
> thanks!
> --  ben
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
> <CsInstruments>
> sr     = 44100
> ksmps  = 32
> nchnls = 2
> 0dbfs  = 1
>
>
> instr 1
>     iBool = 1
>     if (iBool == 0) then
>         iTest = 20
>     else
>         iOther = 10
>     endif
>     print iTest
> endin
>
>
> </CsInstruments>
> <CsScore>
> i 1   0   1
> e
> </CsScore>
> </CsoundSynthesizer>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




Date2013-05-01 21:51
FromJustin Smith
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
This is as much an issue of semantics as the practicality of implementation. ML family languages have a separate compile stage and will complain if something is referenced in a context where it could potentially have not been initialized (because of their scoping rules - if a variable was created in the context of an if branch, every usage of that variable would need to happen inside that same branch).


On Wed, May 1, 2013 at 1:41 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
That is because of the interpreted nature of Python. Csound does not work like that, because the compilation and run times are separate.

On 1 May 2013, at 21:23, Ben Hackbarth wrote:

agreed, but there are other languages where this is not the case, like in python:

b=1
if b == 0:
    test=0
print test

... in which case python throws a NameError.  

since, afaik, you cannot create variables in csound without also assigning their value (unlike C), i had assumed that asking for a variable that was not explicitly inited should result in an error.  i did not think that retrieving garbage was even possible.

but i'm not really a programmer, so if this does not seem suspect to yall, its ok by me.  however, it would be helpful if this was documented somehow.

thanks victor.




--  ben


On Wed, May 1, 2013 at 2:39 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
In performance, however, both branches seem to be initialised, but it still does not reveal the bug.

On 1 May 2013, at 13:33, Victor Lazzarini wrote:

Note that this is the case in other languages as well. In C:

#include <stdio.h>
int main(){
  int a, b, c;
  scanf("%d", &a);
  if(a) b = 10;
  else c = 0;
  printf("%d\n", c);
  return 0;
}

the compiler will not tell you that c can be used uninitialized, even if you compile this with -Wuninitialized. 



Victor
On 1 May 2013, at 13:09, Victor Lazzarini wrote:

I guess there are two issues here, one that is kind of semantic/syntactical and the other to do with backward compatibility.

The first thing is that the parser will not know in all cases whether a variable is set or not. It will only know if a constant is used (as in your case).
There is no way currently to tell at run time whether a variable has been set or not, before we use it (as far as I know at least).

Secondly, if we implement something that will change this behaviour, we might break existing code and that is a no-go zone.
(This is my opinion, of course. I might be wrong about it breaking existing code)

Victor
On 1 May 2013, at 12:39, Ben Hackbarth wrote:

i see.  is this seen as a feature of csound coding?  if not, why not throw an error similar to those thrown when a user asks for a variable that does not exist?

it seems to me only a point of confusion.  in my experience it makes programming/debugging lots of if-then blocks difficult as one might have variables of the same name in different conditional blocks and then accidentally use previously stored values.  at least, i am running into those kinds of problems at the moment.

--  ben


On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
 The variable is not initialised at any point. The code iTest = 0 (assignment at i-time, not initialisation), just does not run if iBool is 0. The
variable just holds whatever garbage it contains.

You can see this by running the following code:

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iBool = p4
if (iBool == 0) then
iTest = 20
else
iOther = 10
endif
print iTest
endin


</CsInstruments>
<CsScore>
i 1 0 1 0
i 1 1 1 1
e
</CsScore>
</CsoundSynthesizer>

It will be set to 20 in the first run of instr 1, and then will keep this value in the second, since it's reusing the memory space of the
first run (as only one allocation is needed).

Victor
On 1 May 2013, at 11:46, Ben Hackbarth wrote:

> hello!
>
> in the csd pasted below, an i-rate variable is initialized in an if-then block and then printed.  however, in the case of this example, the variable isn't initialized since the conditional does not evaluate true.  strangely, csound (5 and 6) does not complain, and assigns the variable a value of zero.  if seems to me that either the user shouldn't be allowed to initialize variables inside conditionals OR csound should exit with an error in this case.  i much prefer the latter.
>
> am i missing something?
>
> thanks!
> --  ben
>
>
> <CsoundSynthesizer>
> <CsOptions>
> -n
> </CsOptions>
> <CsInstruments>
> sr     = 44100
> ksmps  = 32
> nchnls = 2
> 0dbfs  = 1
>
>
> instr 1
>     iBool = 1
>     if (iBool == 0) then
>         iTest = 20
>     else
>         iOther = 10
>     endif
>     print iTest
> endin
>
>
> </CsInstruments>
> <CsScore>
> i 1   0   1
> e
> </CsScore>
> </CsoundSynthesizer>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie



------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel



Date2013-05-01 21:54
FromSteven Yi
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
Hi Ben,

There's a bit to consider in looking at the issue.  First, Csound has
two scopes, global or local.  There are no block-level scopes.  To
understand how this could have happened, I think we need to look at
Csound before if-then's.  In that case, when there is only if-goto's,
there is only a flat list and no syntax blocks. When if-then was
introduced, I don't think there was attention given to scope
variables, just a matter of using if-then as syntax sugar for if-goto.

Other languages like python/c/c++/java/etc. all end up having
variables scoped by blocks. They have issues with name shadowing, but
this is all explained up front in learning these languages.

The way I interpret what you're saying regarding things being an error
is that you expected there to be variable scoping and there isn't at
the moment.  I think it makes sense to have scopes. On the other hand,
older pieces may break due to requiring an additional variable
initialization outside of the blocks to get it to be scoped. Also,
because variable definition and usage are one in the same with Csound,
you couldn't do shadowing of vars (for better or for worse).

steven


On Wed, May 1, 2013 at 9:23 PM, Ben Hackbarth  wrote:
> agreed, but there are other languages where this is not the case, like in
> python:
>
> b=1
> if b == 0:
>     test=0
> print test
>
> ... in which case python throws a NameError.
>
> since, afaik, you cannot create variables in csound without also assigning
> their value (unlike C), i had assumed that asking for a variable that was
> not explicitly inited should result in an error.  i did not think that
> retrieving garbage was even possible.
>
> but i'm not really a programmer, so if this does not seem suspect to yall,
> its ok by me.  however, it would be helpful if this was documented somehow.
>
> thanks victor.
>
>
>
>
> --  ben
>
>
> On Wed, May 1, 2013 at 2:39 PM, Victor Lazzarini 
> wrote:
>>
>> In performance, however, both branches seem to be initialised, but it
>> still does not reveal the bug.
>>
>> On 1 May 2013, at 13:33, Victor Lazzarini wrote:
>>
>> Note that this is the case in other languages as well. In C:
>>
>> #include 
>> int main(){
>>   int a, b, c;
>>   scanf("%d", &a);
>>   if(a) b = 10;
>>   else c = 0;
>>   printf("%d\n", c);
>>   return 0;
>> }
>>
>> the compiler will not tell you that c can be used uninitialized, even if
>> you compile this with -Wuninitialized.
>>
>>
>>
>> Victor
>> On 1 May 2013, at 13:09, Victor Lazzarini wrote:
>>
>> I guess there are two issues here, one that is kind of
>> semantic/syntactical and the other to do with backward compatibility.
>>
>> The first thing is that the parser will not know in all cases whether a
>> variable is set or not. It will only know if a constant is used (as in your
>> case).
>> There is no way currently to tell at run time whether a variable has been
>> set or not, before we use it (as far as I know at least).
>>
>> Secondly, if we implement something that will change this behaviour, we
>> might break existing code and that is a no-go zone.
>> (This is my opinion, of course. I might be wrong about it breaking
>> existing code)
>>
>> Victor
>> On 1 May 2013, at 12:39, Ben Hackbarth wrote:
>>
>> i see.  is this seen as a feature of csound coding?  if not, why not throw
>> an error similar to those thrown when a user asks for a variable that does
>> not exist?
>>
>> it seems to me only a point of confusion.  in my experience it makes
>> programming/debugging lots of if-then blocks difficult as one might have
>> variables of the same name in different conditional blocks and then
>> accidentally use previously stored values.  at least, i am running into
>> those kinds of problems at the moment.
>>
>> --  ben
>>
>>
>> On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini
>>  wrote:
>>>
>>>  The variable is not initialised at any point. The code iTest = 0
>>> (assignment at i-time, not initialisation), just does not run if iBool is 0.
>>> The
>>> variable just holds whatever garbage it contains.
>>>
>>> You can see this by running the following code:
>>>
>>> 
>>> 
>>> -n
>>> 
>>> 
>>> sr = 44100
>>> ksmps = 32
>>> nchnls = 2
>>> 0dbfs = 1
>>>
>>>
>>> instr 1
>>> iBool = p4
>>> if (iBool == 0) then
>>> iTest = 20
>>> else
>>> iOther = 10
>>> endif
>>> print iTest
>>> endin
>>>
>>>
>>> 
>>> 
>>> i 1 0 1 0
>>> i 1 1 1 1
>>> e
>>> 
>>> 
>>>
>>> It will be set to 20 in the first run of instr 1, and then will keep this
>>> value in the second, since it's reusing the memory space of the
>>> first run (as only one allocation is needed).
>>>
>>> Victor
>>> On 1 May 2013, at 11:46, Ben Hackbarth wrote:
>>>
>>> > hello!
>>> >
>>> > in the csd pasted below, an i-rate variable is initialized in an
>>> > if-then block and then printed.  however, in the case of this example, the
>>> > variable isn't initialized since the conditional does not evaluate true.
>>> > strangely, csound (5 and 6) does not complain, and assigns the variable a
>>> > value of zero.  if seems to me that either the user shouldn't be allowed to
>>> > initialize variables inside conditionals OR csound should exit with an error
>>> > in this case.  i much prefer the latter.
>>> >
>>> > am i missing something?
>>> >
>>> > thanks!
>>> > --  ben
>>> >
>>> >
>>> > 
>>> > 
>>> > -n
>>> > 
>>> > 
>>> > sr     = 44100
>>> > ksmps  = 32
>>> > nchnls = 2
>>> > 0dbfs  = 1
>>> >
>>> >
>>> > instr 1
>>> >     iBool = 1
>>> >     if (iBool == 0) then
>>> >         iTest = 20
>>> >     else
>>> >         iOther = 10
>>> >     endif
>>> >     print iTest
>>> > endin
>>> >
>>> >
>>> > 
>>> > 
>>> > i 1   0   1
>>> > e
>>> > 
>>> > 
>>> >
>>> > ------------------------------------------------------------------------------
>>> > Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>>> > Get 100% visibility into your production application - at no cost.
>>> > Code-level diagnostics for performance bottlenecks with <2% overhead
>>> > Download for free and get started troubleshooting in minutes.
>>> >
>>> > http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>>> > Csound-devel mailing list
>>> > Csound-devel@lists.sourceforge.net
>>> > https://lists.sourceforge.net/lists/listinfo/csound-devel
>>>
>>> Dr Victor Lazzarini
>>> Senior Lecturer
>>> Dept. of Music
>>> NUI Maynooth Ireland
>>> tel.: +353 1 708 3545
>>> Victor dot Lazzarini AT nuim dot ie
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>>> Get 100% visibility into your production application - at no cost.
>>> Code-level diagnostics for performance bottlenecks with <2% overhead
>>> Download for free and get started troubleshooting in minutes.
>>> http://p.sf.net/sfu/appdyn_d2d_ap1
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>>
>> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>> Dr Victor Lazzarini
>> Senior Lecturer
>> Dept. of Music
>> NUI Maynooth Ireland
>> tel.: +353 1 708 3545
>> Victor dot Lazzarini AT nuim dot ie
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>>
>> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>> Dr Victor Lazzarini
>> Senior Lecturer
>> Dept. of Music
>> NUI Maynooth Ireland
>> tel.: +353 1 708 3545
>> Victor dot Lazzarini AT nuim dot ie
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>>
>> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>> Dr Victor Lazzarini
>> Senior Lecturer
>> Dept. of Music
>> NUI Maynooth Ireland
>> tel.: +353 1 708 3545
>> Victor dot Lazzarini AT nuim dot ie
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>> http://p.sf.net/sfu/appdyn_d2d_ap1
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>
>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2013-05-01 22:29
FromBen Hackbarth
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
AttachmentsNone  None  
hi steven,

thanks for your comments -- you're correct in that the scoping of variables is precisely the issue. 

when i say that i _expect_ an error, what i mean is that i _want_ an error.  as i rarely write good code the first time, i am counting on csound's complaints to correct my mistakes.  the lack of errors makes it much harder to program efficiently.

again, i can't speak to the particulars of programming language design.  just as a composer who wants to spend as much as possible on music :)

--  ben


On Wed, May 1, 2013 at 10:54 PM, Steven Yi <stevenyi@gmail.com> wrote:
Hi Ben,

There's a bit to consider in looking at the issue.  First, Csound has
two scopes, global or local.  There are no block-level scopes.  To
understand how this could have happened, I think we need to look at
Csound before if-then's.  In that case, when there is only if-goto's,
there is only a flat list and no syntax blocks. When if-then was
introduced, I don't think there was attention given to scope
variables, just a matter of using if-then as syntax sugar for if-goto.

Other languages like python/c/c++/java/etc. all end up having
variables scoped by blocks. They have issues with name shadowing, but
this is all explained up front in learning these languages.

The way I interpret what you're saying regarding things being an error
is that you expected there to be variable scoping and there isn't at
the moment.  I think it makes sense to have scopes. On the other hand,
older pieces may break due to requiring an additional variable
initialization outside of the blocks to get it to be scoped. Also,
because variable definition and usage are one in the same with Csound,
you couldn't do shadowing of vars (for better or for worse).

steven


On Wed, May 1, 2013 at 9:23 PM, Ben Hackbarth <hackbarth@gmail.com> wrote:
> agreed, but there are other languages where this is not the case, like in
> python:
>
> b=1
> if b == 0:
>     test=0
> print test
>
> ... in which case python throws a NameError.
>
> since, afaik, you cannot create variables in csound without also assigning
> their value (unlike C), i had assumed that asking for a variable that was
> not explicitly inited should result in an error.  i did not think that
> retrieving garbage was even possible.
>
> but i'm not really a programmer, so if this does not seem suspect to yall,
> its ok by me.  however, it would be helpful if this was documented somehow.
>
> thanks victor.
>
>
>
>
> --  ben
>
>
> On Wed, May 1, 2013 at 2:39 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie>
> wrote:
>>
>> In performance, however, both branches seem to be initialised, but it
>> still does not reveal the bug.
>>
>> On 1 May 2013, at 13:33, Victor Lazzarini wrote:
>>
>> Note that this is the case in other languages as well. In C:
>>
>> #include <stdio.h>
>> int main(){
>>   int a, b, c;
>>   scanf("%d", &a);
>>   if(a) b = 10;
>>   else c = 0;
>>   printf("%d\n", c);
>>   return 0;
>> }
>>
>> the compiler will not tell you that c can be used uninitialized, even if
>> you compile this with -Wuninitialized.
>>
>>
>>
>> Victor
>> On 1 May 2013, at 13:09, Victor Lazzarini wrote:
>>
>> I guess there are two issues here, one that is kind of
>> semantic/syntactical and the other to do with backward compatibility.
>>
>> The first thing is that the parser will not know in all cases whether a
>> variable is set or not. It will only know if a constant is used (as in your
>> case).
>> There is no way currently to tell at run time whether a variable has been
>> set or not, before we use it (as far as I know at least).
>>
>> Secondly, if we implement something that will change this behaviour, we
>> might break existing code and that is a no-go zone.
>> (This is my opinion, of course. I might be wrong about it breaking
>> existing code)
>>
>> Victor
>> On 1 May 2013, at 12:39, Ben Hackbarth wrote:
>>
>> i see.  is this seen as a feature of csound coding?  if not, why not throw
>> an error similar to those thrown when a user asks for a variable that does
>> not exist?
>>
>> it seems to me only a point of confusion.  in my experience it makes
>> programming/debugging lots of if-then blocks difficult as one might have
>> variables of the same name in different conditional blocks and then
>> accidentally use previously stored values.  at least, i am running into
>> those kinds of problems at the moment.
>>
>> --  ben
>>
>>
>> On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini
>> <Victor.Lazzarini@nuim.ie> wrote:
>>>
>>>  The variable is not initialised at any point. The code iTest = 0
>>> (assignment at i-time, not initialisation), just does not run if iBool is 0.
>>> The
>>> variable just holds whatever garbage it contains.
>>>
>>> You can see this by running the following code:
>>>
>>> <CsoundSynthesizer>
>>> <CsOptions>
>>> -n
>>> </CsOptions>
>>> <CsInstruments>
>>> sr = 44100
>>> ksmps = 32
>>> nchnls = 2
>>> 0dbfs = 1
>>>
>>>
>>> instr 1
>>> iBool = p4
>>> if (iBool == 0) then
>>> iTest = 20
>>> else
>>> iOther = 10
>>> endif
>>> print iTest
>>> endin
>>>
>>>
>>> </CsInstruments>
>>> <CsScore>
>>> i 1 0 1 0
>>> i 1 1 1 1
>>> e
>>> </CsScore>
>>> </CsoundSynthesizer>
>>>
>>> It will be set to 20 in the first run of instr 1, and then will keep this
>>> value in the second, since it's reusing the memory space of the
>>> first run (as only one allocation is needed).
>>>
>>> Victor
>>> On 1 May 2013, at 11:46, Ben Hackbarth wrote:
>>>
>>> > hello!
>>> >
>>> > in the csd pasted below, an i-rate variable is initialized in an
>>> > if-then block and then printed.  however, in the case of this example, the
>>> > variable isn't initialized since the conditional does not evaluate true.
>>> > strangely, csound (5 and 6) does not complain, and assigns the variable a
>>> > value of zero.  if seems to me that either the user shouldn't be allowed to
>>> > initialize variables inside conditionals OR csound should exit with an error
>>> > in this case.  i much prefer the latter.
>>> >
>>> > am i missing something?
>>> >
>>> > thanks!
>>> > --  ben
>>> >
>>> >
>>> > <CsoundSynthesizer>
>>> > <CsOptions>
>>> > -n
>>> > </CsOptions>
>>> > <CsInstruments>
>>> > sr     = 44100
>>> > ksmps  = 32
>>> > nchnls = 2
>>> > 0dbfs  = 1
>>> >
>>> >
>>> > instr 1
>>> >     iBool = 1
>>> >     if (iBool == 0) then
>>> >         iTest = 20
>>> >     else
>>> >         iOther = 10
>>> >     endif
>>> >     print iTest
>>> > endin
>>> >
>>> >
>>> > </CsInstruments>
>>> > <CsScore>
>>> > i 1   0   1
>>> > e
>>> > </CsScore>
>>> > </CsoundSynthesizer>
>>> >
>>> > ------------------------------------------------------------------------------
>>> > Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>>> > Get 100% visibility into your production application - at no cost.
>>> > Code-level diagnostics for performance bottlenecks with <2% overhead
>>> > Download for free and get started troubleshooting in minutes.
>>> >
>>> > http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>>> > Csound-devel mailing list
>>> > Csound-devel@lists.sourceforge.net
>>> > https://lists.sourceforge.net/lists/listinfo/csound-devel
>>>
>>> Dr Victor Lazzarini
>>> Senior Lecturer
>>> Dept. of Music
>>> NUI Maynooth Ireland
>>> tel.: +353 1 708 3545
>>> Victor dot Lazzarini AT nuim dot ie
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>>> Get 100% visibility into your production application - at no cost.
>>> Code-level diagnostics for performance bottlenecks with <2% overhead
>>> Download for free and get started troubleshooting in minutes.
>>> http://p.sf.net/sfu/appdyn_d2d_ap1
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>>
>> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>> Dr Victor Lazzarini
>> Senior Lecturer
>> Dept. of Music
>> NUI Maynooth Ireland
>> tel.: +353 1 708 3545
>> Victor dot Lazzarini AT nuim dot ie
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>>
>> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>> Dr Victor Lazzarini
>> Senior Lecturer
>> Dept. of Music
>> NUI Maynooth Ireland
>> tel.: +353 1 708 3545
>> Victor dot Lazzarini AT nuim dot ie
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>>
>> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>> Dr Victor Lazzarini
>> Senior Lecturer
>> Dept. of Music
>> NUI Maynooth Ireland
>> tel.: +353 1 708 3545
>> Victor dot Lazzarini AT nuim dot ie
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>> http://p.sf.net/sfu/appdyn_d2d_ap1
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>
>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>

------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


Date2013-05-08 23:46
FromSteven Yi
SubjectRe: [Cs-dev] (buggy?) variable initialization with if-then
Hi Ben,

Just following up on this email, I think we'll have to file looking
into variable scoping and blocks post-6.0. It's a large enough change
that I don't think it can be scheduled in.  At least for the time
being, we're following the same semantics as is found in 5.x and are
thus backwards compatible.

I'm guessing that the only possible solution moving forward is to
adopt a  backwards compatibility flag, some kind of compiler pragma,
or somewhere in-between. Ideally, by default we could turn on scoped
vars, and have the option to turn it off if running older projects.
If it's a real legacy project that just isn't going to get updated,
there'll be the possibility to run it.  Otherwise the scoped behavior
could be on and things may break, but at least it should be easy
enough to update.  Having scoped vars does promote better programming
practices I think in this scenario.  Other than that, I don't really
see another way around it.

Thanks!
steven


On Wed, May 1, 2013 at 10:29 PM, Ben Hackbarth  wrote:
> hi steven,
>
> thanks for your comments -- you're correct in that the scoping of variables
> is precisely the issue.
>
> when i say that i _expect_ an error, what i mean is that i _want_ an error.
> as i rarely write good code the first time, i am counting on csound's
> complaints to correct my mistakes.  the lack of errors makes it much harder
> to program efficiently.
>
> again, i can't speak to the particulars of programming language design.
> just as a composer who wants to spend as much as possible on music :)
>
> --  ben
>
>
> On Wed, May 1, 2013 at 10:54 PM, Steven Yi  wrote:
>>
>> Hi Ben,
>>
>> There's a bit to consider in looking at the issue.  First, Csound has
>> two scopes, global or local.  There are no block-level scopes.  To
>> understand how this could have happened, I think we need to look at
>> Csound before if-then's.  In that case, when there is only if-goto's,
>> there is only a flat list and no syntax blocks. When if-then was
>> introduced, I don't think there was attention given to scope
>> variables, just a matter of using if-then as syntax sugar for if-goto.
>>
>> Other languages like python/c/c++/java/etc. all end up having
>> variables scoped by blocks. They have issues with name shadowing, but
>> this is all explained up front in learning these languages.
>>
>> The way I interpret what you're saying regarding things being an error
>> is that you expected there to be variable scoping and there isn't at
>> the moment.  I think it makes sense to have scopes. On the other hand,
>> older pieces may break due to requiring an additional variable
>> initialization outside of the blocks to get it to be scoped. Also,
>> because variable definition and usage are one in the same with Csound,
>> you couldn't do shadowing of vars (for better or for worse).
>>
>> steven
>>
>>
>> On Wed, May 1, 2013 at 9:23 PM, Ben Hackbarth  wrote:
>> > agreed, but there are other languages where this is not the case, like
>> > in
>> > python:
>> >
>> > b=1
>> > if b == 0:
>> >     test=0
>> > print test
>> >
>> > ... in which case python throws a NameError.
>> >
>> > since, afaik, you cannot create variables in csound without also
>> > assigning
>> > their value (unlike C), i had assumed that asking for a variable that
>> > was
>> > not explicitly inited should result in an error.  i did not think that
>> > retrieving garbage was even possible.
>> >
>> > but i'm not really a programmer, so if this does not seem suspect to
>> > yall,
>> > its ok by me.  however, it would be helpful if this was documented
>> > somehow.
>> >
>> > thanks victor.
>> >
>> >
>> >
>> >
>> > --  ben
>> >
>> >
>> > On Wed, May 1, 2013 at 2:39 PM, Victor Lazzarini
>> > 
>> > wrote:
>> >>
>> >> In performance, however, both branches seem to be initialised, but it
>> >> still does not reveal the bug.
>> >>
>> >> On 1 May 2013, at 13:33, Victor Lazzarini wrote:
>> >>
>> >> Note that this is the case in other languages as well. In C:
>> >>
>> >> #include 
>> >> int main(){
>> >>   int a, b, c;
>> >>   scanf("%d", &a);
>> >>   if(a) b = 10;
>> >>   else c = 0;
>> >>   printf("%d\n", c);
>> >>   return 0;
>> >> }
>> >>
>> >> the compiler will not tell you that c can be used uninitialized, even
>> >> if
>> >> you compile this with -Wuninitialized.
>> >>
>> >>
>> >>
>> >> Victor
>> >> On 1 May 2013, at 13:09, Victor Lazzarini wrote:
>> >>
>> >> I guess there are two issues here, one that is kind of
>> >> semantic/syntactical and the other to do with backward compatibility.
>> >>
>> >> The first thing is that the parser will not know in all cases whether a
>> >> variable is set or not. It will only know if a constant is used (as in
>> >> your
>> >> case).
>> >> There is no way currently to tell at run time whether a variable has
>> >> been
>> >> set or not, before we use it (as far as I know at least).
>> >>
>> >> Secondly, if we implement something that will change this behaviour, we
>> >> might break existing code and that is a no-go zone.
>> >> (This is my opinion, of course. I might be wrong about it breaking
>> >> existing code)
>> >>
>> >> Victor
>> >> On 1 May 2013, at 12:39, Ben Hackbarth wrote:
>> >>
>> >> i see.  is this seen as a feature of csound coding?  if not, why not
>> >> throw
>> >> an error similar to those thrown when a user asks for a variable that
>> >> does
>> >> not exist?
>> >>
>> >> it seems to me only a point of confusion.  in my experience it makes
>> >> programming/debugging lots of if-then blocks difficult as one might
>> >> have
>> >> variables of the same name in different conditional blocks and then
>> >> accidentally use previously stored values.  at least, i am running into
>> >> those kinds of problems at the moment.
>> >>
>> >> --  ben
>> >>
>> >>
>> >> On Wed, May 1, 2013 at 1:30 PM, Victor Lazzarini
>> >>  wrote:
>> >>>
>> >>>  The variable is not initialised at any point. The code iTest = 0
>> >>> (assignment at i-time, not initialisation), just does not run if iBool
>> >>> is 0.
>> >>> The
>> >>> variable just holds whatever garbage it contains.
>> >>>
>> >>> You can see this by running the following code:
>> >>>
>> >>> 
>> >>> 
>> >>> -n
>> >>> 
>> >>> 
>> >>> sr = 44100
>> >>> ksmps = 32
>> >>> nchnls = 2
>> >>> 0dbfs = 1
>> >>>
>> >>>
>> >>> instr 1
>> >>> iBool = p4
>> >>> if (iBool == 0) then
>> >>> iTest = 20
>> >>> else
>> >>> iOther = 10
>> >>> endif
>> >>> print iTest
>> >>> endin
>> >>>
>> >>>
>> >>> 
>> >>> 
>> >>> i 1 0 1 0
>> >>> i 1 1 1 1
>> >>> e
>> >>> 
>> >>> 
>> >>>
>> >>> It will be set to 20 in the first run of instr 1, and then will keep
>> >>> this
>> >>> value in the second, since it's reusing the memory space of the
>> >>> first run (as only one allocation is needed).
>> >>>
>> >>> Victor
>> >>> On 1 May 2013, at 11:46, Ben Hackbarth wrote:
>> >>>
>> >>> > hello!
>> >>> >
>> >>> > in the csd pasted below, an i-rate variable is initialized in an
>> >>> > if-then block and then printed.  however, in the case of this
>> >>> > example, the
>> >>> > variable isn't initialized since the conditional does not evaluate
>> >>> > true.
>> >>> > strangely, csound (5 and 6) does not complain, and assigns the
>> >>> > variable a
>> >>> > value of zero.  if seems to me that either the user shouldn't be
>> >>> > allowed to
>> >>> > initialize variables inside conditionals OR csound should exit with
>> >>> > an error
>> >>> > in this case.  i much prefer the latter.
>> >>> >
>> >>> > am i missing something?
>> >>> >
>> >>> > thanks!
>> >>> > --  ben
>> >>> >
>> >>> >
>> >>> > 
>> >>> > 
>> >>> > -n
>> >>> > 
>> >>> > 
>> >>> > sr     = 44100
>> >>> > ksmps  = 32
>> >>> > nchnls = 2
>> >>> > 0dbfs  = 1
>> >>> >
>> >>> >
>> >>> > instr 1
>> >>> >     iBool = 1
>> >>> >     if (iBool == 0) then
>> >>> >         iTest = 20
>> >>> >     else
>> >>> >         iOther = 10
>> >>> >     endif
>> >>> >     print iTest
>> >>> > endin
>> >>> >
>> >>> >
>> >>> > 
>> >>> > 
>> >>> > i 1   0   1
>> >>> > e
>> >>> > 
>> >>> > 
>> >>> >
>> >>> >
>> >>> > ------------------------------------------------------------------------------
>> >>> > Introducing AppDynamics Lite, a free troubleshooting tool for
>> >>> > Java/.NET
>> >>> > Get 100% visibility into your production application - at no cost.
>> >>> > Code-level diagnostics for performance bottlenecks with <2% overhead
>> >>> > Download for free and get started troubleshooting in minutes.
>> >>> >
>> >>> >
>> >>> > http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> >>> > Csound-devel mailing list
>> >>> > Csound-devel@lists.sourceforge.net
>> >>> > https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >>>
>> >>> Dr Victor Lazzarini
>> >>> Senior Lecturer
>> >>> Dept. of Music
>> >>> NUI Maynooth Ireland
>> >>> tel.: +353 1 708 3545
>> >>> Victor dot Lazzarini AT nuim dot ie
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> ------------------------------------------------------------------------------
>> >>> Introducing AppDynamics Lite, a free troubleshooting tool for
>> >>> Java/.NET
>> >>> Get 100% visibility into your production application - at no cost.
>> >>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> >>> Download for free and get started troubleshooting in minutes.
>> >>> http://p.sf.net/sfu/appdyn_d2d_ap1
>> >>> _______________________________________________
>> >>> Csound-devel mailing list
>> >>> Csound-devel@lists.sourceforge.net
>> >>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >>
>> >>
>> >>
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> >> Get 100% visibility into your production application - at no cost.
>> >> Code-level diagnostics for performance bottlenecks with <2% overhead
>> >> Download for free and get started troubleshooting in minutes.
>> >>
>> >>
>> >> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> >> Csound-devel mailing list
>> >> Csound-devel@lists.sourceforge.net
>> >> https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >>
>> >>
>> >> Dr Victor Lazzarini
>> >> Senior Lecturer
>> >> Dept. of Music
>> >> NUI Maynooth Ireland
>> >> tel.: +353 1 708 3545
>> >> Victor dot Lazzarini AT nuim dot ie
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> >> Get 100% visibility into your production application - at no cost.
>> >> Code-level diagnostics for performance bottlenecks with <2% overhead
>> >> Download for free and get started troubleshooting in minutes.
>> >>
>> >>
>> >> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> >> Csound-devel mailing list
>> >> Csound-devel@lists.sourceforge.net
>> >> https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >>
>> >>
>> >> Dr Victor Lazzarini
>> >> Senior Lecturer
>> >> Dept. of Music
>> >> NUI Maynooth Ireland
>> >> tel.: +353 1 708 3545
>> >> Victor dot Lazzarini AT nuim dot ie
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> >> Get 100% visibility into your production application - at no cost.
>> >> Code-level diagnostics for performance bottlenecks with <2% overhead
>> >> Download for free and get started troubleshooting in minutes.
>> >>
>> >>
>> >> http://p.sf.net/sfu/appdyn_d2d_ap1_______________________________________________
>> >> Csound-devel mailing list
>> >> Csound-devel@lists.sourceforge.net
>> >> https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >>
>> >>
>> >> Dr Victor Lazzarini
>> >> Senior Lecturer
>> >> Dept. of Music
>> >> NUI Maynooth Ireland
>> >> tel.: +353 1 708 3545
>> >> Victor dot Lazzarini AT nuim dot ie
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> >> Get 100% visibility into your production application - at no cost.
>> >> Code-level diagnostics for performance bottlenecks with <2% overhead
>> >> Download for free and get started troubleshooting in minutes.
>> >> http://p.sf.net/sfu/appdyn_d2d_ap1
>> >> _______________________________________________
>> >> Csound-devel mailing list
>> >> Csound-devel@lists.sourceforge.net
>> >> https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >>
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> > Get 100% visibility into your production application - at no cost.
>> > Code-level diagnostics for performance bottlenecks with <2% overhead
>> > Download for free and get started troubleshooting in minutes.
>> > http://p.sf.net/sfu/appdyn_d2d_ap1
>> > _______________________________________________
>> > Csound-devel mailing list
>> > Csound-devel@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/csound-devel
>> >
>>
>>
>> ------------------------------------------------------------------------------
>> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
>> Get 100% visibility into your production application - at no cost.
>> Code-level diagnostics for performance bottlenecks with <2% overhead
>> Download for free and get started troubleshooting in minutes.
>> http://p.sf.net/sfu/appdyn_d2d_ap1
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>
>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net