236

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

Comments
  • 8
    Cache invalidation and naming things ...
  • 13
    Coming up with variable names when they store similar data
  • 77
    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
  • 10
    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

    Eg.

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

    Return returnVal;
    }
  • 2
    I face the same issue everyday
  • 22
    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'
  • 0
    Why does it do more than one thing ((@))_((@))?
  • 2
    @mintu19
    'K.i.s.s.'
    Keep it simple stupid.

    @everyoneCommentingThatFunctionsShouldOnlyDoOneThing
    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)
    piosh.suc(slngrmv)
    btchcntr = Prnlvr.antvar(1)
    }
    // 200 more lines of code that does it all
    }
Add Comment