implicit return? [🇷 for BE/BA]

posted by Helmut Homepage – Vienna, Austria, 2019-04-28 22:50 (2018 d 17:55 ago) – Posting: # 20257
Views: 8,081

Dear Detlew,

❝ ❝ I always use explicit return(something) in my functions,…


❝ A good idea.


Yep.

❝ But if you use R you are told that doing so has the penalty of a longer run-time.

❝ Bloody Hell!


Does that really matter?
library(microbenchmark)
impl <- function(x) {
  if (x == 0) {
    "foo"
  } else {
    "bar"
  }
}
expl <- function(x) {
  if (x == 0) {
    return("foo")
  } else {
    return("bar")
  }
}
res <- microbenchmark(impl(round(runif(1), 0)),
                      expl(round(runif(1), 0)), times=2000L)
print(res)

Unit: microseconds
                     expr   min    lq     mean median    uq      max neval cld
 impl(round(runif(1), 0)) 1.811 1.812 2.686167  1.813 2.114 1383.479  2000   a
 expl(round(runif(1), 0)) 1.811 1.812 2.955002  1.813 2.114 1879.152  2000   a


❝ Weakly typed (R) against strong typed language (C or C++).


Exactly. You know that I’m facing a similar story with the forum scripts (PHP: weakly typed) generating database-queries (SQL: strongly typed). Bloody scavenger hunt.

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes

Complete thread:

UA Flag
Activity
 Admin contact
23,288 posts in 4,890 threads, 1,658 registered users;
29 visitors (1 registered, 28 guests [including 7 identified bots]).
Forum time: 15:46 CET (Europe/Vienna)

‘Normal science’ means research firmly based upon one or more
past scientific achievements, achievements that some particular
scientific community acknowledges for a time as supplying
the foundation for its further practice.    Thomas S. Kuhn

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5