24 thoughts on “Q: What do you call a function with no arguments?

  1. I use functions whenever I have repeated blocks of code, or even when a function gets too big to understand in a quick glance. When within classes and acting on objects stored in class properties, there’s no need to pass anything to it in many cases.

    Like

  2. Those are not functions in this sense because they have side effects which need careful management and they also cannot be used in unit tests without special handling.

    If you are not returning the same result for the same arguments then what you have is really a “procedure” or a “sub routine”. Calling it a function is an abuse of terminology (but one with a very long history). Hence we distinguish real functions from this by calling them “pure” functions.

    Functions are not just there to facilitate code reuse (they are a lot more useful than that). Even so, pure functions are much more reusable and testable than impure ones.

    Like

  3. It’s the same thing. A function without a return or a function that returns different results for the same arguments is not really a function. It’s a member of a broader category of subroutine.

    Like

  4. Programmers do like to abuse mathematics at every possible opportunity. The thing is, a more algebraic approach to programming actually leads to better code. It’s a hard sell however. It’s taken 50 years to get most developers up to the state of the art (circa 1967).

    Like

  5. John Hardy Turnbull delenda est John McCarthy created LISP (The LIST PROCESSING language) 1958. He thought that a disturbing bug, the problem with dynamic bindings of variables, would be solved within one year.

    It took a bit longer…

    Like

  6. John Hardy Turnbull delenda est and object programming paradigm are a “much” later approach to programming, in the form of the ALGOL 60 extended programming language SIMULA 67 in the paper by Dahl and Nygaard about classes and subclasses.

    Like

  7. Yes lexical scope came out of the work of one of his students who just expected values to reflect where they appeared in the source. Dynamic scope is very counterintuitive but common enough is low level languages. Wasn’t that one of the big selling points of Scheme?

    Object Oriented Programming was just a mistake in my opinion. An understandable one perhaps but still a mistake. It took all the hard won lessons of computer science and threw them out the window.

    Like

  8. John Hardy Turnbull delenda est I belive that schema has lexical scope as selling point, so do Common Lisp.

    The Lisp in Emacs uses dynamic scope and uses it heavily, so it can’t be fixed easily. But there are some package for Common Lisp support.

    Problem with dynamic scope are the compiler will have problem catch errors and miss spellings.

    Object oriented are great for what it was designed for, event based simulations (SIMULA is named after that).

    Not so good when it comes to other stuff. People tend to use a hammer on everything, even bolts and screws.

    The problem with functional programming is that the computers didn’t had enough power early on. It is just lately (last 20 years) that HW started to catch up. Now we have to do that too… 🙂

    Like

  9. Anders Jackson interestingly, there are some pretty good optimizing compilers for a more than a few functional programming languages out there now that produce very efficient binaries. (But this was a more recent discovery of computer science.)

    This isn’t really too surprising given that most modern optimizing compilers tend to include a step where the program is reduced to a Static Single-Assignment (SSA) normal form.

    A pure functional language basically enforces SSA normal form at the language level, so pure functional languages can be very aggressively optimized.

    Like

  10. Anders Jackson Emacs has lexical binding these days. The problem is that you have to enable it on a per-file basis, in order to preserve backwards compatbility. They are moving to making all standard packages use it, however

    Like

  11. Elias MÃ¥rtenson isn’t what comes with the Common Lisp module?

    Yes, you would like to change all programs to that, but too much is based on dynamic binding and not lexical.

    That is good to hear. I have to read up on Emacs state, I hear. Thanks for the information.

    Like

  12. Ramin Honary well. The functional programming languages are much easier to write a compiler, with optimization, than other programming language paradigms like in C and Java.

    Just because there are no Aliasing problem which you get with pointers. So you can have many names of the same data storage.

    And because you don’t have variable semantics like those procedural programming languages. Variables are actually alias of calculations, so it’s much easier to handle memory management, and thus optimize these use.

    And no, that is not so much new discovery. I looked into those optimization parts in computer science courses in the mid 1990. At least in Uppsala and Edinburgh, which had good functional research environments. I studied in Uppsala, where we did some research on Erlang. In Edinburgh they was more into pure programming, before monads and such.

    Like

  13. Anders Jackson

    And no, that is not so much new discovery. I looked into those optimization parts in computer science courses in the mid 1990.

    Yes, I meant “more recent” relative to the invention of Lisp. So these innovations would’t have existed back in the early 1960s even though at that time optimizing functional languages would have been considerably more important than it is today when we have an abundance of computing power.

    Like

Leave a comment