1. Oops! I threw a return value in the trash by mistake

See a problem here?

atom idx = 0 find(tabname, cntxNames) 
if idx > 0 then 

Oops! No wonder idx is always equal to 0. *facepalm*

new topic     » topic index » view message » categorize

2. Re: Oops! I threw a return value in the trash by mistake

ryanj said...

See a problem here?

atom idx = 0 find(tabname, cntxNames) 
if idx > 0 then 

Oops! No wonder idx is always equal to 0. *facepalm*

I'm surprised there doesn't seem to be a warning for discarded function return values. See Complex with / without options.

I think this would have been a logical addition to the warning system when the ability to discard return values was introduced. Unless I missed something.

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Oops! I threw a return value in the trash by mistake

ghaberek said...

I'm surprised there doesn't seem to be a warning for discarded function return values. See Complex with / without options.

I think this would have been a logical addition to the warning system when the ability to discard return values was introduced. Unless I missed something.

-Greg

I agree.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Oops! I threw a return value in the trash by mistake

In Phix you have to code an explicit discard:

{} = find(tabname, cntxNames) 
new topic     » goto parent     » topic index » view message » categorize

5. Re: Oops! I threw a return value in the trash by mistake

petelomax said...

In Phix you have to code an explicit discard:

{} = find(tabname, cntxNames) 

I proposed an explicit discard as well, but Jeremy turned it down and IIRC the votes were in his favor.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Oops! I threw a return value in the trash by mistake

The other one me and my clumsy fingers are often grateful for is

if length(x=0) then 

which in Phix generates the compile-time error "incompatible type for routine signature" - unlike OE you would need sq_eq(x,0) to deliver anything other than a single T/F, and length(atom) is fatal, not 1.

Obviously I meant

if length(x)=0 then 

and I probably make that error roughly once every other month, especially when writing expressions containing several nested brackets.
Then again maybe I get a bit careless because I know the compiler will help me.

new topic     » goto parent     » topic index » view message » categorize

7. Re: Oops! I threw a return value in the trash by mistake

petelomax said...

The other one me and my clumsy fingers are often grateful for is

if length(x=0) then 

which in Phix generates the compile-time error "incompatible type for routine signature" - unlike OE you would need sq_eq(x,0) to deliver anything other than a single T/F, and length(atom) is fatal, not 1.

When length() was updated to include atoms the change caught me completely by surprise. But it's more of a nuisance than a big problem so I never did anything about it. I would have coded this line as:

if not ~x then 

But this has its own problem since the tilde, while quick to type, is also easy to omit. So then would I ever return to using length()? - N e v e r

As for discarded return values, I think I had this in Orac before OE. What I also added at the time was a method to analyse the program (wholly or by module) which could find all functions invoked as if they were procedures.

Spock

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu