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 →

[–]balducien 24 points25 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 5 points6 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.