Re: How can I combine this into one line of code?

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...
DerekParnell said...
writef("What is [] + []?", {first_number, second_number}) 

Derek, when would one use printf() vs. writef()? Is printf() going to be phased out or does it still have its place?

Good question. printf is not going to go away as far as I can see. The choice as to which one to use will depend on your requirements.

The advantages of writef are...

  • simpler tags. You don't need %s, %d, %f etc just [] for all data types.
  • you can specify the order of the arguments in the tags.
    • writef("[2] follows [1]", {"day, night"}) comes out as "night follows day".
  • There are more output options than printf, eg. binary, octal and hex numbers.
  • The tag syntax is a little more forgiving about how you code it.

The advantage of printf, for now any way, is that it is faster as it is a built-in routine and not a library routine.

We use writef internally in Euphoria for error messages because we need to specify the word order to cater for other languages when messages are translated.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu