Independent & Effeciency :: Programming Concepts
Hi.
I began learning C++ and programming for the first time about ten months ago. I love programming using C++. Whether I am using C++, MFC, or Winsock, programming concepts never change.
C++ is an extremely powerful programming language and is one of the most extensive programming language. I find myself often trying to decide one programming style and weighing effeciency, effectiveness, reusabiliy, and manageability for future changes.
What is most important: Independent or Effeciency?
Here is one example. Let consider there is a function that does a mathematicaly calculation. However, there are different types of data such as int and double. In this case, is it better to write two separate functions where each performs a task for a specific data type, or is it better to use a switch or if/else state inside one function and manipulate data relative to whatever datatype that is passed in? This is just one example. There are many more complicated scenarios.
Ultimately, my concern here is about "slick" programming or "safe" programming.
-> many lines of code : easier to expand
Is it better to have everything independent, i.e. one function for every job and for every data type? This might seem redundant.
-> few lines of code : difficult to expand
Is it better to use "tricks" and cram everything togetter to make programs smaller and maybe more efficient? This might seems difficult to expand in the future. What if you want to add a new feature and needs to add something to a function; however, this feature only applies to one datatype or one scenario.
Thanks,
Kuphryn
Re: Independent & Effeciency :: Programming Concepts
Quote:
Originally posted by kuphryn
Hi.
-> many lines of code : easier to expand
Is it better to have everything independent, i.e. one function for every job and for every data type? This might seem redundant.
-> few lines of code : difficult to expand
Is it better to use "tricks" and cram everything togetter to make programs smaller and maybe more efficient? This might seems difficult to expand in the future. What if you want to add a new feature and needs to add something to a function; however, this feature only applies to one datatype or one scenario.
personally, I dont worry about either. you cant halve the size of an enterprise application with tricks, nor will overcoding make it easier to read.
i know you were talking only of 1 function, but what does one function mean in the context of the app. nothing, if you cram it with tricks and remove two lines of code that equates to 10 bytes, which you dont see since the compiler rounded the code segment to a paragraph... etc.
the best thing to do is neither size nore speed, its efficiency. desk check the function and see how well the flow of it works.