Page 1 of 1

Remove of #pb_any

Posted: Sat Oct 22, 2011 6:28 pm
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

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 6:31 pm
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.

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 6:33 pm
by GPI
not the first time. Thats why i want an option in the compiler. Old code - set flag and it will work.

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 6:34 pm
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!! :)

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 7:07 pm
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.

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 7:53 pm
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:

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 7:59 pm
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.

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 8:49 pm
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.

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 8:57 pm
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.

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 9:42 pm
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".

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 10:23 pm
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.

Re: Remove of #pb_any

Posted: Sat Oct 22, 2011 11:59 pm
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

Re: Remove of #pb_any

Posted: Sun Oct 23, 2011 12:07 am
by Polo
I'd rather have to type PB Any than to change all functions names and lose the help tooltip...