Trying to come up with function names when it does more than one thing.

  • 8
    Cache invalidation and naming things ...
  • 14
    Coming up with variable names when they store similar data
  • 80
    If a function does more than one thing, isn't that a sign that it's doing too much?
  • 4
    More just "trying to name things" for me
  • 11
    Just concat the things it does with "And", and you will find out your code stinks.
  • 2
    @Jantho1990 ya it is.... I have about 30 functions with just one line xD
  • 4
    Shouldn't it be split into separate functions?

    Then if you want to call a function that does all the other functions give it a group name


    Function getFieldNum()
    Function calculateInterest()
    Function getFieldInterest{
    Var returnVal = calculateInterest (getFieldNum(this));

    Return returnVal;
  • 2
    I face the same issue everyday
  • 24
    I have a name for it: thisFunctionShouldBeRefactored
  • 3
    @Jantho1990 Indeed, that would be the S (Single responsibility) from the SOLID principle.
  • 2
    I once named a function: makeTeacherThenClassThenLogin
  • 1
    But why though is it doing more than one thing?
  • 1
    ...Don't do two things in one function. Easier to test and maintain anyway
  • 2
    That tag... 'kiss'
  • 1
    Why does it do more than one thing ((@))_((@))?
  • 2
    Keep it simple stupid.

    Well duh! That's the point.
  • 2
    @jAsE Just like "in the old days" use weird abbreviations for argument and function names nobody can ever figure out what they are supposed to do but is pronounceable as a weird word. And that words sound corny or perverted but actually are abbreviations for accounting or marketing terms. So when you discuss that code in the kitchen next to the coffee maker everybody thinks you have some kind of brain damage. And just do it in one huuuge function like (pseudocode ahead):

    coclsh(char clufuc, array piosh )
    btchcntr = 0
    while (btchcntr < Dipsht.topsltcnt()
    slngrmv = Slngprn.cnv(clufuc)
    btchcntr = Prnlvr.antvar(1)
    // 200 more lines of code that does it all
Add Comment