MyProcedureWithOptionalParams(a.l = 42, *b.POINT = {8,15})

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

MyProcedureWithOptionalParams(a.l = 42, *b.POINT = {8,15})

Post by traumatic »

Now that we have optional, pre-initialized parameters it would be more
than useful to also be able to use this feature for structures IMHO:

Code: Select all

Procedure  MyProcedureWithOptionalParams(a.l = 42, *b.POINT = {8,15})
 ; *b\x = 8, *b\y = 15
EndProcedure
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Hmm! That looks rather messy.

Personally I'd rather have:

Code: Select all

  Structure MyPoint
    x.l=1
    y.l=2
  EndStructure
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

and then?
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Thats it!


Your idea would mean dynamic structures.

Remember, default values are only used if there is no value.

A structure is fixed, it does not change.
Currently a structure defaults all it's variables to 0.
So my idea make sense.

Your would not work without major changes to PB's handling of structures.

Ever tried to reference a variable in a structure and the variable did not exist?
Your idea would possibly have that issue all the time.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Rescator wrote:Your idea would mean dynamic structures.
No, I think you misunderstood what I meant.

You can do x.l = 5 but you can't do x.POINT = {5,5} (same for arrays)

While there's a good way to fill in the values with macros now, there's
no way to use a pointer to a structure as an optional argument.
Good programmers don't comment their code. It was hard to write, should be hard to read.
Post Reply