fb suggestion to reduce vertical code size

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

fb suggestion to reduce vertical code size

Post by dafhi »

I often create variables to illustrate parameters

Code: Select all

var x = 50
var y = 50
var rad = 50

mycircle.draw x, y, rad, color, outlined
If it's not too difficult, create a way where one could simply

Code: Select all

mycircle.draw var:x=50, var:y=50, var:rad=50
just an idea. i'd hack fb myself if i felt i could.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: fb suggestion to reduce vertical code size

Post by paul doe »

A better option would be simply to use the literal, eh? The syntax you propose, while certainly more readable, has no real purpose (the variable's scope is limited to just the call). However, other languages (like VB) allow named parameters, which allows, among other things, to pass parameters to the call in any order:

Code: Select all

function foo( bar as long, baz as string ) as integer
  return( whatever )
end function

var f = foo( baz: = "Test", bar: = 4 )
Is this what you really meant?
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: fb suggestion to reduce vertical code size

Post by dafhi »

that's better than what i meant; mine's way too verbose haha!

but i think one-time-use vars ARE useful in a mnemonic sense.

mixed param order seems pretty usseful .. if i couldn't remember i could just say
i want my radius 50, x 10, y 10

yes i do like
Post Reply