Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:59:05+00:00 2026-06-01T11:59:05+00:00

I’m just wondering – is it bad programming style to create functions (decomposition) for

  • 0

I’m just wondering – is it bad programming style to create functions (decomposition) for relatively simple task?

For example, in PHP I find it annoying to have the ‘$_’ and then capital letters for session, post, get, and cookies. So if I made a function called setSesVar(‘key’, ‘value’) that would create a session variable for me, is that bad? And is the overhead of calling a function for it each time worth it? Or is it irrelevant/own preference?

Some other examples:

  • printLn function in c++ (and java)
  • shorthand form of getElementBydId in Javascript (assuming I don’t use jQuery or another library)
  • redirect in place of header(‘Location: ‘ . url) in PHP

And a slightly off topic question – I’m use to languages with more ‘strict’ arrays; in PHP you can add an element to the end buy just saying myArray[] = ‘newElement’. I feel like I should do myArray[sizeof(myArray)] but I bet it’s probably bad style to add unessesary code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:59:06+00:00Added an answer on June 1, 2026 at 11:59 am

    Depends on what the functions do, and how much you’re doing this. If you take everything and make a one-line function out of it, then you haven’t really gotten rid of any complexity. In fact, you’ve added complexity, in two ways:

    • First, anything that’s not built into PHP is something someone new to your code has to figure out. If i see $_SESSION['stuff'] = "some value";, i know what it’s doing — as does anyone who’s spent more than an hour with PHP. On the other hand, if i see setSessionVar('stuff', 'some value');, i have to go and make sure of what setSessionVar does. I mean, it’s got to be doing something more than just setting something in $_SESSION; otherwise, why not just do that?

    • Second, if these functions end up calling each other, you end up with a rats’ nest of function calls. It’s easier to follow a 10- (or even a 30-) line function than to trace through a 2-line function that calls this other 2-line function that calls this whole other 2-line function that might or might not call another 2-line function. You’d have to yoyo through the file (or worse, tab between a bunch of different files) in order to trace your way through the code.

    In my opinion, anything that’s built into PHP — and can be expressed in one simple line of code — does not deserve its own function. I’d suggest limiting functions to at least 3 lines, with one exception: methods that require access to an object’s internals, like getters or setters for example, can be smaller. But most functions should do something that PHP doesn’t already trivially do; if they don’t, then you’re defeating the purpose of functions and adding complexity for no good reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.