Most active commenters

    ←back to thread

    173 points todsacerdoti | 42 comments | | HN request time: 2.195s | source | bottom
    1. userbinator ◴[] No.44506358[source]
    Somewhat less frequently, I also hear "invoke" or "execute", which is more verbose but also more generic.

    Incidentally, I find strange misuses of "call" ("calling a command", "calling a button") one of the more grating phrases used by ESL CS students.

    replies(7): >>44506396 #>>44506421 #>>44506500 #>>44506580 #>>44510160 #>>44510878 #>>44511635 #
    2. pansa2 ◴[] No.44506396[source]
    > strange misuses of "call"

    My favourite (least favourite?) is using “call” with “return”. On more than one occasion I’ve heard:

    “When we call the return keyword, the function ends.”

    replies(4): >>44506779 #>>44506910 #>>44506977 #>>44511912 #
    3. treyd ◴[] No.44506421[source]
    I actually see the converse often with novices often, referring to statements (or even entire function decls) as "commands".
    replies(1): >>44506617 #
    4. Dwedit ◴[] No.44506500[source]
    C# seems to like to use "Invoke" for things like delegates or reflected methods. Then it proceeds to use "Call Stack" in the debugger view.
    replies(2): >>44509956 #>>44512011 #
    5. spudlyo ◴[] No.44506580[source]
    Invoke comes from Latin invocō, invocāre, meaning “to call upon”. I wouldn’t view it as a misuse, but rather a shortening.
    replies(1): >>44506845 #
    6. kragen ◴[] No.44506617[source]
    "Command" is a better term for what we call "statements" in imperative programming languages. "Statement" in this context is an unfortunate historical term; except in Prolog, these "statements" don't have a truth-value, just an effect. (And in Prolog we call them "clauses" instead.)
    replies(1): >>44510711 #
    7. jamesfinlayson ◴[] No.44506779[source]
    I remember someone in university talking about the if function (which ostensibly takes one boolean argument).
    replies(5): >>44506886 #>>44506915 #>>44507329 #>>44508128 #>>44509940 #
    8. thaumasiotes ◴[] No.44506845[source]
    > Invoke comes from Latin invocō, invocāre, meaning “to call upon”.

    (In the way you'd call upon a skill, not in the way you'd call upon a neighbor.)

    replies(3): >>44509492 #>>44509604 #>>44512457 #
    9. Findecanor ◴[] No.44506886{3}[source]
    There are languages in which `if` is a function.

    In in Tcl, `if` is called a "command".

    replies(1): >>44509377 #
    10. userbinator ◴[] No.44506910[source]
    I've heard that too --- the voice in my head automatically read it in the customary thick Indian accent.
    11. weinzierl ◴[] No.44506915{3}[source]
    Sounds like something Prof. John Ousterhout would say:-; The place where this was literally accurate would be Tcl.

    I don't know enough Smalltalk to be sure but I think to remember it has a similar approach of everything is an object and I wouldn't be surprised if they'd coerced control flow somehow into this framework.

    Also Forth comes to mind, but that would probably be a stretch.

    replies(2): >>44509778 #>>44511669 #
    12. pwdisswordfishz ◴[] No.44506977[source]
    Eh, "return" is just a very restricted continuation with special syntax… it's a stretch to say you "call" it, but not unjustified.
    13. antonvs ◴[] No.44507329{3}[source]
    Try implementing that in most languages and you'll run into problems.

    In an imperative programming language with eager evaluation, i.e. where arguments are evaluated before applying the function, implementing `if` as a function will evaluate both the "then" and "else" alternatives, which will have undesirable behavior if the alternatives can have side effects.

    In a pure but still eager functional language this can work better, if it's not possible for the alternatives to have side effects. But it's still inefficient, because you're evaluating expressions whose result will be discarded, which is just wasted computation.

    In a lazy functional language, you can have a viable `if` function, because it will only evaluate the argument that's needed. But even in the lazy functional language Haskell, `if` is implemented as built-in syntax, for usability reasons - if the compiler understands what `if` means as opposed to treating it as an ordinary function, it can optimize better, produce better messages, etc.

    In a language with the right kind of macros, you can define `if` as a macro. Typically in that case, its arguments might be wrapped in lambdas, by the macro, to allow them to be evaluated only as needed. But Scheme and Lisp, which have the right kind of macros, don't define `if` as a macro for similar reasons to Haskell.

    One language in which `if` is a function is the pure lambda calculus, but no-one writes real code in that.

    The only "major" language I can think of in which `if` is actually a function (well, a couple of methods) is Smalltalk, and in that case it works because the arguments to it are code blocks, i.e. essentially lambdas.

    tl;dr: `if` as a function isn't practical in most languages.

    replies(1): >>44509661 #
    14. Delphiza ◴[] No.44508128{3}[source]
    In Excel formulas everything is a function. IF, AND, OR, NOT are all functions. It is awkward and goes against what software devs are familiar with, but there are probably more people familiar with the Excel IF function than any other forms. Here is an example taken from the docs... =IF(AND(A3>B2,A3<C2),TRUE,FALSE)
    replies(1): >>44508460 #
    15. EForEndeavour ◴[] No.44508460{4}[source]
    Excel cell formulas are the most widely used functional programming language in the world.
    16. spacechild1 ◴[] No.44509377{4}[source]
    Also in Smalltalk and sclang (Supercollider language)
    replies(1): >>44510065 #
    17. exe34 ◴[] No.44509492{3}[source]
    Which fits nicely for calling a function - you use its skill, you don't call for a chat.
    18. coldtea ◴[] No.44509604{3}[source]
    But vocare (the voco in invoco) is how you'd call a neighbor
    19. immibis ◴[] No.44509661{4}[source]
    I don't think Haskell needs 'if' to be a construct for compiler optimization reasons; it could be implemented easily enough with pattern matching:

    if' :: Bool -> a -> a -> a

    if' True x _ = x

    if' False _ y = y

    The compiler could substitute this if it knew the first argument was a constant.

    Maybe it was needed in early versions. Or maybe they just didn't know they wouldn't need it yet. The early versions of Haskell had pretty terrible I/O, too.

    replies(1): >>44510086 #
    20. kevindamm ◴[] No.44509778{4}[source]
    I would include the cond function from lisp, or the generalization from lambda calculus

       λexpr1.λexpr2.λc.((c expr1) expr2)
    21. Zambyte ◴[] No.44509940{3}[source]
    If takes two or three arguments, but never one. The condition is the one made syntactically obvious in most languages, the consequent is another required argument, and the alternative is optional.
    replies(1): >>44510291 #
    22. Zambyte ◴[] No.44509956[source]
    Microsoft devs get paid by the character, I'm not sure that counts.
    23. kitd ◴[] No.44510065{5}[source]
    Or anything Lispy
    24. fn-mote ◴[] No.44510086{5}[source]
    A short search lead to this SE post [1], which doesn't answer the "why" but says "if" is just syntactic sugar that turns into `ifThenElse`...

    [1]: https://softwareengineering.stackexchange.com/questions/1957...

    The post claims that this is done in such a basic way that if you have managed to rebind `ifThenElse`, your rebound function gets called. I didn't confirm this, but I believed it.

    replies(1): >>44512176 #
    25. kgwxd ◴[] No.44510160[source]
    Now that it's commonly "tap or click the button" I might be down with the next gen using "call". Anything, as long as they don't go with "broh, the button".
    26. dylan604 ◴[] No.44510291{4}[source]
    Huh? if (true) {} takes precisely one argument.
    replies(1): >>44510378 #
    27. mjburgess ◴[] No.44510378{5}[source]
    That's an application of `if` with one of the arguments empty.

    The semantics of `if` requrie at least, `if(cond, clause)`, though more generally, `if(cond, clause, else-clause)`

    replies(1): >>44510682 #
    28. devnullbrain ◴[] No.44510682{6}[source]
    You and Zambyte are both doing the same thing the top level comment is complaining about.

    e.g. in C:

    https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf

        (6.8.5.1) selection-statement:
          if ( expression ) secondary-block
          if ( expression ) secondary-block else secondary-block
    
    in C++:

    https://eel.is/c++draft/gram.stmt

        selection-statement:
          if constexpropt ( init-statementopt condition ) statement
          if constexpropt ( init-statementopt condition ) statement else statement
          if !opt consteval compound-statement
          if !opt consteval compound-statement else statement
    
    where

        condition:
          expression
          attribute-specifier-seqopt decl-specifier-seq declarator brace-or-equal-initializer
          structured-binding-declaration initializer 
    
    More examples:

    https://docs.python.org/3/reference/grammar.html

    https://doc.rust-lang.org/reference/expressions/if-expr.html...

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

    expression != argument

    replies(1): >>44510881 #
    29. adrian_b ◴[] No.44510711{3}[source]
    True.

    In many early computer programming documents the term "order" was used instead of "statement", where "order" was meant as a synonym for "command" and not as referring to the ordering of a sequence.

    replies(1): >>44511605 #
    30. 1718627440 ◴[] No.44510878[source]
    On an old Nokia you follow links by pressing the call button.
    31. smilliken ◴[] No.44510881{7}[source]
    They aren't talking about C and its descendants in particular, but more generally. For example in Haskell and Scheme there is only an if function and no if statement. And you're welcome to create an if function in any language you like and use it instead of the native syntax. I like to use an if function in PostgreSQL because it's less cumbersome than a case expression.

    So in the abstract, if is a ternary function. I think the original comment was reflecting on how "if (true) ... " looks like a function call of one argument but that's obviously wrong.

    replies(2): >>44511305 #>>44511773 #
    32. devnullbrain ◴[] No.44511305{8}[source]
    Arguments are expressions in Haskell. In abstract, it uses expressions.
    33. kragen ◴[] No.44511605{4}[source]
    Occasionally, but much more often (as in Mauchly's cited paper) an "order" was a machine instruction, not a high-level language "statement".
    replies(1): >>44512439 #
    34. zahlman ◴[] No.44511635[source]
    >Incidentally, I find strange misuses of "call" ("calling a command", "calling a button") one of the more grating phrases used by ESL CS students.

    From my own experience, native speakers (who are beginners at programming) also do this. They also describe all kinds of things as "commands" that aren't.

    35. zahlman ◴[] No.44511669{4}[source]
    > I don't know enough Smalltalk to be sure but I think to remember it has a similar approach of everything is an object and I wouldn't be surprised if they'd coerced control flow somehow into this framework.

    It does. It's been discussed on HN before, even: https://news.ycombinator.com/item?id=13857174

    36. disconcision ◴[] No.44511773{8}[source]
    this is not quite right. haskell and scheme have if expressions, not if statements. that's not the same as if being a function. if is not, and cannot be, a function in scheme, as it does not have scheme function semantics. specifically, it is not strict, as it does not evaluate all its subexpressions before executing. since haskell is non-strict, if can be implemented as a function, and iirc it is
    replies(1): >>44512138 #
    37. layer8 ◴[] No.44511912[source]
    Some people use parentheses for the return value, to make it look like a function call:

        return(value);
    38. ◴[] No.44512011[source]
    39. trealira ◴[] No.44512138{9}[source]
    > since haskell is non-strict, if can be implemented as a function, and iirc it is

    "If" can be implemented as a function in Haskell, but it's not a function. You can't pass it as a higher-order function and it uses the "then" and "else" keywords, too. But you could implement it as a function if you wanted:

      if' :: Bool -> a -> a
      if' True x _ = x
      if' False _ y = y
    
    Then instead of writing something like this:

      max x y = if x > y then x else y
    
    You'd write this:

      max x y = if' (x > y) x y
    
    But the "then" and "else" remove the need for parentheses around the expressions.
    40. ◴[] No.44512176{6}[source]
    41. adrian_b ◴[] No.44512439{5}[source]
    Yes, but that is mostly because in the first few years (including by the time of Mauchly), there were no "high-level" programming languages, so the "orders" composing the text of a program corresponded to instructions directly executable by the machine.

    I believe that the term "statement" has been imposed by the IBM publications about FORTRAN, starting in 1956.

    Before the first public documents about IBM FORTRAN, the first internal document about FORTRAN, from 1954, had used the terms "formula" for anything that later would be called "executable statement", i.e. for many things that would not have been called formulas either before or after that, like IF-formulas, DO-formulas, GOTO-formulas and so on, and the document had used "sentence" for what later would be called "non-executable statements" (i.e. definitions or declarations).

    Before FORTRAN (1951 to 1953), for his high-level programming language Heinz Rutishauser had used the term "Befehl", which means "command". (For what we name today "program", he had used the term "Rechenplan", which means "computation plan".)

    42. marcosdumay ◴[] No.44512457{3}[source]
    It's calling a person like by saying their name loudly.