Forums

yes = true

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

yes = true

Postby ebaker355 » Thu Jul 07, 2011 9:00 am

I'm brand new to Cobra, and it looks fantastic! Is there a way I can substitute (like 'typedef', '#define', macro, etc.) the "true" keyword with "yes", and "false" with "no"? It's just a personal preference, but for my poor brain, code like:

Code: Select all
success = yes
failed = no

is more readable than:

Code: Select all
success = true
failed = false

Any way to do this type of keyword substitution in Cobra?
Thanks!
ebaker355
 
Posts: 2

Re: yes = true

Postby Charles » Thu Jul 07, 2011 3:03 pm

Thanks. Regarding the keyword substitution, no. In fact, Cobra's syntax generally prefers fewer ways to do a particular thing so that it's easier to read code between developers, examples, wiki pages, etc.

But if you really wanted to, you could try this:
extend Object

def yes as bool
return true

def no as bool
return false

# ...

success = .yes

Note that you need the leading period to access the extension methods. Also, Cobra does not look inside methods, so it won't really "know" that .yes is always true. Probably not a big deal, but something to consider.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: yes = true

Postby ebaker355 » Fri Jul 08, 2011 9:55 am

Great! Thanks for the reply! Extending object is a nice workaround. Very helpful.
ebaker355
 
Posts: 2


Return to Discussion

Who is online

Users browsing this forum: No registered users and 34 guests