Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There is no one size fits all.

In a many cases I'd still rather have three or more versions of a function, many which may just be very thin shims to accommodate that scenario than 10 copy/pastes of variations. Or shim at the call site and keep one function if that suits.



If a function does different things in different circumstances it should usually be split into different functions.

Languages like Erlang which can have different versions of a function, selected by pattern matching (with optional guards) make this convenient:

    Name(Pattern11,...,Pattern1N) [when GuardSeq1] ->
        Body1;
    ...;
    Name(PatternK1,...,PatternKN) [when GuardSeqK] ->
        BodyK.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: