Remove of #pb_any

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Remove of #pb_any

Post by GPI »

as a optional parameter in the compiler options (default off).
so instead of

Code: Select all

ofile=OpenFile(#PB_Any, "Test.txt")    ; öffnet eine existierende Datei oder erstellt eine, wenn sie noch nicht existiert
If ofile
    FileSeek(ofile, Lof(0))         ; springt an das Ende der Datei (das Ergebnis von Lof() wird hierfür verwendet)
    WriteStringN(ofile, "... another line at the end.")
    CloseFile(ofile)
EndIf
it should be

Code: Select all

 ofile=OpenFile( "Test.txt")    ; öffnet eine existierende Datei oder erstellt eine, wenn sie noch nicht existiert
If ofile
    FileSeek(ofile, Lof(0))         ; springt an das Ende der Datei (das Ergebnis von Lof() wird hierfür verwendet)
    WriteStringN(ofile, "... another line at the end.")
    CloseFile(ofile)
EndIf
Maybe it is possible to use it as an optional parameter.

maybe it would be nice something like this:

Code: Select all

if openfile(@ofile,"test.txt")
 FileSeek(ofile, Lof(0))         ; springt an das Ende der Datei (das Ergebnis von Lof() wird hierfür verwendet)
    WriteStringN(ofile, "... another line at the end.")
    CloseFile(ofile)
EndIf
at the moment something linke this is possible:

Code: Select all

Procedure.i myreadfile(*var.integer,file$)
  *var\i=ReadFile(#PB_Any,file$)
  ProcedureReturn *var\i
EndProcedure

Macro ReadFile(a,b)
  myreadfile(@a,b)
EndMacro

If ReadFile(ofile, "Test.txt")
  Debug "gefunden!"+Str(ofile)
  CloseFile(ofile)
Else 
  Debug "das war nichts"
EndIf
If ReadFile(ofile, "c:\windows\directx.log")
  Debug "gefunden!"+Str(ofile)
  CloseFile(ofile)
Else 
  Debug "das war nichts"
EndIf
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Remove of #pb_any

Post by Polo »

I second this. I hardly ever use OpenWindow(0,...) and hate to type #pb_any all the time...!
It'd break many existing code however.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Remove of #pb_any

Post by GPI »

not the first time. Thats why i want an option in the compiler. Old code - set flag and it will work.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Remove of #pb_any

Post by Polo »

GPI wrote:not the first time. Thats why i want an option in the compiler. Old code - set flag and it will work.
That would be very good indeed!! :)
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Remove of #pb_any

Post by STARGÅTE »

PureBasic can not work with different parameter types!

Code: Select all

OpenFile("Test.txt")
OpenFile(@File, "Test.txt")
The first parameter must always be either a number or a string always.

PureBasic has found a good way to work with indexes and any-numbers.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Remove of #pb_any

Post by luis »

I found the current PB implementation stylish and logical: a constant number OR #pb_any, and always the return value positive on success.

Setting a parameter to change this in the options is not nice, the code shared in the forums could not work on another configuration.

I like it the way it is, so I vote against a change. :wink:
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: Remove of #pb_any

Post by kenmo »

Polo wrote:It'd break many existing code however.
It doesn't break existing code when required parameters become optional, only when optional parameters become required.

OpenFile(0, "file") and OpenFile(#PB_Any, "file") can still work, but OpenFile("file") could also be allowed and default to ID = #PB_Any.

But like Stargate said, I think PB currently requires optional parameters to be at the end, so that the type of the 1st, 2nd, etc. argument won't change.

Maybe it's possible, it would be a nice little syntax change. For now a simple macro will do the same thing.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Remove of #pb_any

Post by netmaestro »

I vote against this change. #PB_Any is already confusing enough for coders new to Purebasic, this would only make it more so.
BERESHEIT
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Remove of #pb_any

Post by GPI »

Than removing it would make it easier for new coders ;)

I think that use a numeric is a very old methode - for example the basic on the c64 use it. It is simple, but the problem is, that you must know what are you doing to avoid conflicts. Thats why no new programming language use this any more.

not long ago, the openwindow-command has changed. So that everybody must change there code isn't realy a argument.
Ramihyn_
Enthusiast
Enthusiast
Posts: 314
Joined: Fri Feb 24, 2006 9:40 am

Re: Remove of #pb_any

Post by Ramihyn_ »

GPI wrote:So that everybody must change there code isn't realy a argument.
The amount of work needed due to code changes should at least be outweighted by some advantage due to the change. But beside the abstract goal of "a cleaner language", i don't see the advantage of this suggestion. You can easily write a macro to fix this for yourself without forcing anybody to work over their existing sources. Such a change would also affect quite a lot source lines.

But in general i agree that the whole parameter is a bit "pointless".
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Remove of #pb_any

Post by GPI »

thats maybe the best solution with the optional Parameter in the Source-Code. The compiler should detect, that, for example, openfile("test.txt") has only one parameter und should give the Errormessage "Open File():Incorrect Numbers of Parameter. Maybe you should activate 'Manual Handle Support' in the Compiler Options" - same for the constant #pb_any. So the user get a hind, how he can solve the problem.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Remove of #pb_any

Post by MachineCode »

Why not just macro it? You can even put the macro in a Residents file so you don't need to type the macros in new sources.

Code: Select all

Macro CreateAFile(name)
  CreateFile(#PB_Any,name)
EndMacro

f$="c:\test.txt"

f=CreateAFile(f$) ; No need to type #PB_Any! Woohoo!
If f
  CloseFile(f)
  DeleteFile(f$)
EndIf
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Remove of #pb_any

Post by Polo »

I'd rather have to type PB Any than to change all functions names and lose the help tooltip...
Post Reply