Contemplating on this ...

BlitzMax Forums/BlitzMax Programming/Contemplating on this ...

beanage(Posted 2009) [#1]
Programming my scripting language, i came around the idea of following:
If my_condition Then my_flag!

as a shortcut for..
If my_condition Then my_flag=TRUE; Else my_flag=FALSE

Just _imagining_ this was a bmax feature, would this collide with the double/long (?) literal?

Would you use such a shortcut?


Tachyon(Posted 2009) [#2]
Shortcuts suck. It saves you 0.5 seconds of typing but make code 10 times more unreadable.


matibee(Posted 2009) [#3]
What's it a shortcut for? If my_condition returns true or false;

my_flag = my_condition

if it returns (for example) a number where zero = false and any non-zero eqls true;

my_flag = my_condition > 0


beanage(Posted 2009) [#4]
You are right. Didnt think so far :/
Perfect workaround for object conditions:
Local my_object :Object
Local my_flag :Int
my_flag = my_object<>Null

It just anyhow jumped into my mind, that the exclamation mark made real sense there .. :)


therevills(Posted 2009) [#5]
Sounds a bit like the ternary operator:

my_flag = my_condition ? TRUE : FALSE;


Is the same as:

If my_condition Then my_flag=TRUE Else my_flag=FALSE


But this isnt in BlitzMax....


Htbaa(Posted 2009) [#6]
In Perl you can use this instead of the tenary operator.
my $var = $something || 'nothing';


This shortcut would be nice to have in BlitzMax :-).


beanage(Posted 2009) [#7]
I am so interested in programming languages at all .. when i have time next, i will check out Perl..


Jim Teeuwen(Posted 2009) [#8]
The ! and ? have varying uses depending on language, I doubt it really fits into the blitz universe though (never mind that it denotes a Double data type).

In Ruby and Erlang, for instance, appending a function name with ! tells you that this function actively changes the contents of any passed arguments or the class in which it is contained. Or 'in-place' as it is called. Something like this:

str = "  abcdef  "
str.trim!()
puts "#{str}"


It will print 'abcdef' because the 'Str.trim!()' call means that 'Str' is changed in-place, so you don't have to do Str = Str.trim() instead.

Same deal with ?. It is used as a question mark. Like this:

def Awesome?(a)
  return false if a < 0
  return true
end
if Awesome?(4)
  puts "yay"
end


In this case, it is more obviously syntactical sugar. It just reads easier and doesn't actually change anything abuot the operation itself. It is perfectly valid to use the above without the question mark.


I am so interested in programming languages at all



I have that to. I'm not so much interested in writing cool apps as I am in the languages themselves. That's why I tend to fiddle around and learn to work with as many languages as I can lay my hands on. it's good fun ^^
My interest in languages also extends to natural (spoken) languages.