The title says it all but I am curious if it's acceptable or even efficient for that matter. If others were to read my code or work on a project with me is this generally accepted among others or yourself if you work on an enterprise level? Is this memory efficient to split things up for developer "ease-of-use"?

Recommended Answers

All 5 Replies

I don't agree that "the title says it all". I have no idea what your question is. Programming involves creating and using functions and classes, how could it possibly be not "ok", if you can't create / use functions and classes, you can't do anything. It's like asking "is using a hammer and nails 'ok' for a carpenter?". Please explain what you mean more clearly, and we'll be happy to help.

How would you write code without using functions or classes? From what I know about code creation you want to compartmentalize your code as much as possible. Breaking it up makes it easier to maintain and affords you the ability to change code in one spot and have it apply to your entire project. Lets say you have an algorithm that does a transformation of a number to another number. If you had the code that does that in all of the places you need it that's bad. If you want to change it you would have to go to every spot in your code and change it. If you instead had the code in a function and you called the function every time you needed it then all you have to do is change the code in the function. Its the same problem with magic numbers in your code. If you are using a specific number all over the place in your code make it a constant variable instead of hard coding it everywhere. It makes updating your code a lot easier.

I understand using classes and functions to simplify code but my question was using them to merely organize the actual text for the programmer. An example would be say you have 10 functions that you need a class to use. Is it better to call all ten or call the 10 functions into 1 function with the only use of that function being to call it in our class, therefore only needing 1 function call in our new class.

As software engineering is similar in many ways to architecture, there is a principle that they share: "Form follows function". The principle is summarized as the fact that the form that a construction takes depends primarily on the function or purpose intended for it.

The reason I point this out is that you are asking about the form that code should take, without explaining the purpose or function that the code should accomplish. That can't work. You have to explain the function before you can determine what the best form is.

Is this memory efficient to split things up for developer "ease-of-use"?

Even if it wasn't, it doesn't matter. Code maintainability and readability is a lot more important than shaving off a few bytes here and there. Your time as a developer is a worth more money than a few processor cycles.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.