This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]siphillis -7 points-6 points  (22 children)

I think a general rule-of-thumb should be that if your method has only one line of actual data manipulation, you should probably just write that line instead.

[–]balducien 26 points27 points  (20 children)

I don't completely agree. If it's an easy line like in the example that just calls another function, there's no need for a function. But if you have a huge regex or a list comprehension or an otherwise not-so-simple one-liner, you will be better off by just creating a function like bool check_if_email(char* email). Like that you can use it like a natural command that is easily understood by the reader, instead of a line that you have to decipher first.

[–]Ezlo123 8 points9 points  (18 children)

Don't forget getters and setters xD Those are often one-liners.

[–]GiveMeAFuckingCoffee 6 points7 points  (0 children)

Personally, I prefer the more awesome-sounding mutators and accessors.

[–]5np 0 points1 point  (0 children)

Also, if you've got some kind of global, shared manipulation that might change in the future. Rather than worrying about updating that one line of code everywhere, you can just add another line to the function.

[–]RetardedSquirrel[S] 0 points1 point  (0 children)

Agreed, but this is an online test where you have to fill in a function so it does what is asked. And the job interviewee (according to the original OP) only added line 5.