no output should be "", <<"">> or undefined?

7 views
Skip to first unread message

Franklin Brauning

unread,
Nov 8, 2016, 6:44:46 AM11/8/16
to Nitrogen Project / The Nitrogen Web Framework for Erlang
maybe this is the wrong kind of optimization but on those typical cases like

 case Data of
  undefined -> WHAT SHOULD I EMIT HERE?
  _ -> Data
end

what should I return to waste the less of cpu cycles. I tend to use undefined becasue it
is very explicit but reading some defautl elements it emits no-output as ""

Also I have a not that related question: the WF_IF macros, or any erlang macro,
does it evaluate arguments in an eager fashion or lazy?

?WF_IF(false, 1, do_something())

will do_something() be evaluated ?

Jesse Gumm

unread,
Nov 8, 2016, 8:58:59 AM11/8/16
to nitrogenweb
This kind of optimization is so minimal as to be negligible.  Either <<>> or "" will be basically nothing in terms of processing speed.  The atom undefined should usually not be used in regards to an "emit" value if only because <<>> or "" says "emit an empty string", while 'undefined' being an atom is slightly semantically different: do you want to emit the text 'undefined' or do you want to emit an empty string?

As for ?WF_IF, it's lazy.  It's mostly an alias to case expression wrapped in a Fun (to prevent variable leaking), which means the raw case expressions will be slightly faster:


So with ?WF_IF(false, 1, do_something()),

do_something() will not be called.

-Jesse


--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb+unsubscribe@googlegroups.com.
To post to this group, send email to nitro...@googlegroups.com.
Visit this group at https://groups.google.com/group/nitrogenweb.
For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm
Reply all
Reply to author
Forward
0 new messages