Removed autocasting strings

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Removed autocasting strings

Post by Fred »

Actually, disallowing autocasting of pointers makes sens, as you hardly need it unless you are doing very specific debugging.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Removed autocasting strings

Post by Josh »

Fred wrote:Actually, disallowing autocasting of pointers makes sens, as you hardly need it unless you are doing very specific debugging.
If there will be a option to disallow auto-casting in future, it would make sense to do this in code and not in the preferences. So there will be no problem to use posted code from the forum.

I'm thinking a parameter or flag for different security levels expanding the EnableExplicit directive would make sense.
sorry for my bad english
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Removed autocasting strings

Post by Danilo »

Fred wrote:Actually, disallowing autocasting of pointers makes sens, as you hardly need it unless you are doing very specific debugging.
It is not a problem with pointers only. I think you have luis' example in mind: Write *p where you wanted to write *p\s.
It could be a typo, but this can also happen with structures. Not for string concatenation, generally.

Code: Select all

EnableExplicit

Structure Items
    b.b
EndStructure

Structure Entity
    *p.Byte
    b.Items[10]
EndStructure

Define the.Entity

Define byt.b = 12

If byt = the       ; compare byte (.b) with Structure?
    Debug "1"
EndIf

If byt = the\b[5]  ; compare byte (.b) with Structure?
    Debug "2"
EndIf

If byt = the\p     ; compare byte (.b) with Pointer?
    Debug "3"
EndIf

If byt = the\b[5]\b             ; compare byte (.b) with byte (.b), correct
    Debug "4"
EndIf

If the\p <> 0 And byt = the\p\b ; compare byte (.b) with byte (.b), correct
    Debug "5"
EndIf
PB does auto-casting from nearly all to all types. We know that. But a typo is a typo, it is mistake you did not want to write.

Writing *p or x but wanting to write *p\s and x\b can happen everywhere, not for string concatenation only.

Maybe it would be better to allow everything by default (like it is now) for prototyping
and check EVERYTHING with EnableExplicit. In the case of auto-casting to string,
EnableExplicit would mean to have explicitely to use Str(). ;)
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Removed autocasting strings

Post by Little John »

Josh wrote:If there will be a option to disallow auto-casting in future, it would make sense to do this in code and not in the preferences.
Absolutely!
Josh wrote:So there will be no problem to use posted code from the forum.
I understand what you are saying, but I think then there still will be problems with using posted code from the forum.
Say there will be the keywords "EnableStringAutocasting" and "DisableStringAutocasting". People might use them at the beginning of their main source code file, before any "Include" statement. Then they'll post e.g. a snippet from an include file, which as a small isolated piece of code will not work the same way as in the original context, with "EnableStringAutocasting" or "DisableStringAutocasting" in effect. IMHO this has the potential to cause much confusion.
User avatar
mk-soft
Always Here
Always Here
Posts: 6212
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Removed autocasting strings

Post by mk-soft »

I take back my request to remove the "auto casting".
I like the idea with the "EnableAutocasting, DisableAutocasting".

I first discovered PureBasic for my hobby. In the meantime I use purebasic for special requirements in the industrial application where there are no ready for solving approaches.

The development time of these special applications with purebasic very short.

My request to the PureBasic Team which is the bug reports are processed before any other wish.

Thank you for the best native compiler for all standard OS :wink:

Thanks to google translater
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Removed autocasting strings

Post by Little John »

mk-soft wrote:I take back my request to remove the "auto casting".
Then I'll maintain the request. :)
buddymatkona
Enthusiast
Enthusiast
Posts: 252
Joined: Mon Aug 16, 2010 4:29 am

Re: Removed autocasting strings

Post by buddymatkona »

Making new functionality optional when changing existing commands is easier on users, however, having said that...
If you start Debug with a string, you get autocasting. If you don't, you don't. I like it.
Post Reply