It is currently Wed May 22, 2013 10:26 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 6:28 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1125
as a optional parameter in the compiler options (default off).
so instead of
Code:
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:
 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:
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:
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


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 6:31 pm 
Offline
Addict
Addict

Joined: Tue May 06, 2003 5:07 pm
Posts: 2257
Location: UK
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.


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 6:33 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1125
not the first time. Thats why i want an option in the compiler. Old code - set flag and it will work.


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 6:34 pm 
Offline
Addict
Addict

Joined: Tue May 06, 2003 5:07 pm
Posts: 2257
Location: UK
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!! :)


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 7:07 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 711
Location: Germany, Glienicke
PureBasic can not work with different parameter types!
Code:
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.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 7:53 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 2240
Location: Italy
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:

_________________
[ Home ] [ My PC ] [ New to PB ? ]


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 7:59 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 932
Location: New York
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.


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 8:49 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6465
I vote against this change. #PB_Any is already confusing enough for coders new to Purebasic, this would only make it more so.

_________________
Veni, vidi, vici.


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 8:57 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1125
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.


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 9:42 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 24, 2006 9:40 am
Posts: 290
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".


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 10:23 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1125
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.


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sat Oct 22, 2011 11:59 pm 
Offline
Addict
Addict

Joined: Tue Feb 22, 2011 1:16 pm
Posts: 1459
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:
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!


Top
 Profile  
 
 Post subject: Re: Remove of #pb_any
PostPosted: Sun Oct 23, 2011 12:07 am 
Offline
Addict
Addict

Joined: Tue May 06, 2003 5:07 pm
Posts: 2257
Location: UK
I'd rather have to type PB Any than to change all functions names and lose the help tooltip...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye