Click here to Skip to main content
15,886,919 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
AnswerRe: Navel gazing on coding style? Pin
Mircea Neacsu18-Sep-22 2:05
Mircea Neacsu18-Sep-22 2:05 
GeneralRe: Navel gazing on coding style? Pin
Greg Utas18-Sep-22 3:34
professionalGreg Utas18-Sep-22 3:34 
GeneralRe: Navel gazing on coding style? Pin
0x01AA18-Sep-22 4:40
mve0x01AA18-Sep-22 4:40 
GeneralRe: Navel gazing on coding style? Pin
englebart18-Sep-22 4:53
professionalenglebart18-Sep-22 4:53 
GeneralRe: Navel gazing on coding style? Pin
Daniel Pfeffer18-Sep-22 6:02
professionalDaniel Pfeffer18-Sep-22 6:02 
GeneralRe: Navel gazing on coding style? Pin
obermd19-Sep-22 6:59
obermd19-Sep-22 6:59 
GeneralRe: Navel gazing on coding style? Pin
Mircea Neacsu19-Sep-22 8:43
Mircea Neacsu19-Sep-22 8:43 
AnswerRe: Navel gazing on coding style? Pin
PIEBALDconsult18-Sep-22 5:21
mvePIEBALDconsult18-Sep-22 5:21 
Well, there's style and then there's style.

I am generally pretty set in my style, so I'm unlikely to change it and also I don't try to force my style on others.

BUT, when the "style" can affect performance, I think attention should be paid.
I prefer to have single-return functions -- others prefer multi-return.
I'm not above putting a try/catch in a catch -- others have freaked the Elephant | [mastadon] out at the sight.
A few months ago, I was looking into a function which has both features.
This function gets called for every character in a text file (CSV or JSON for the most part), so performance is important. (I was testing with a 28GB CSV file.)

Which meant I had a good opportunity to test the relative performance of different "styles" of the function
single- vs multi-return
try/catch in a catch vs not (not having the try/catch in a catch required multi-return as well)
So I had six test versions to compare. The results were inconclusive.

On the plus side, I did wind up with a text reader which supports only UTF8 and performs better than the built-in .net Stream Reader (which has to support other encodings).

I may add more to this response later.


(Later)

OK, I want to add a bit. You mentioned having functions with many lines.
Yes, having shorter functions which have a more limited functional scope can be a benefit in most circumstances.
But it can also lead to performance degradation in others. As I worked on the code I mentioned above, this was something I had in mind.
My text file reader needs to be able to replace certain non-ASCI characters (NPSP, "smart"-quotes, etc.) with their ASCII equivalents.
I began with using the built-in StreamReader -- it can read and decode ASCII, UTF8, UTF16, and other encodings (I assume).
ASCII being a subset of UTF8, I need only UTF8. Additionally, using the StreamReader, once I read a character, I lose any information the reader had about its ASCII-ness, which meant that I then needed to test each and every character again to determine whether or not it is ASCII.
But by writing my own reader, I was able to test the ASCII-ness of each character only once and then test only the non-ASCII characters (which are less than 1% of the total characters in the file) for whether or not they are ones I want to replace.


In the real world, FandG ( x ) often out-performs F ( G ( x ) ) -- smaller single-purpose functions are not always better.
Consider how performance suffers when each function in A ( B ( C ( D ( ... ) ) ) ) has to check its input for NULL, or range, or whatever, when we know that the previous function already did that.

modified 18-Sep-22 22:44pm.

AnswerRe: Navel gazing on coding style? Pin
Gerry Schmitz18-Sep-22 6:52
mveGerry Schmitz18-Sep-22 6:52 
GeneralRe: Navel gazing on coding style? Pin
honey the codewitch18-Sep-22 6:57
mvahoney the codewitch18-Sep-22 6:57 
AnswerRe: Navel gazing on coding style? Pin
Eddy Vluggen18-Sep-22 7:47
professionalEddy Vluggen18-Sep-22 7:47 
GeneralRe: Navel gazing on coding style? Pin
honey the codewitch18-Sep-22 8:15
mvahoney the codewitch18-Sep-22 8:15 
GeneralRe: Navel gazing on coding style? Pin
Eddy Vluggen18-Sep-22 8:36
professionalEddy Vluggen18-Sep-22 8:36 
GeneralRe: Navel gazing on coding style? Pin
honey the codewitch18-Sep-22 8:49
mvahoney the codewitch18-Sep-22 8:49 
QuestionRe: Navel gazing on coding style? Pin
Eddy Vluggen18-Sep-22 9:09
professionalEddy Vluggen18-Sep-22 9:09 
AnswerRe: Navel gazing on coding style? Pin
Nelek18-Sep-22 10:39
protectorNelek18-Sep-22 10:39 
AnswerRe: Navel gazing on coding style? Pin
Kate-X25718-Sep-22 22:58
Kate-X25718-Sep-22 22:58 
GeneralRe: Navel gazing on coding style? Pin
honey the codewitch18-Sep-22 23:05
mvahoney the codewitch18-Sep-22 23:05 
AnswerRe: Navel gazing on coding style? Pin
dan!sh 18-Sep-22 22:58
professional dan!sh 18-Sep-22 22:58 
AnswerRe: Navel gazing on coding style? Pin
Cpichols19-Sep-22 1:52
Cpichols19-Sep-22 1:52 
GeneralRe: Navel gazing on coding style? Pin
honey the codewitch19-Sep-22 3:19
mvahoney the codewitch19-Sep-22 3:19 
AnswerRe: Navel gazing on coding style? Pin
SeattleC++19-Sep-22 6:03
SeattleC++19-Sep-22 6:03 
AnswerRe: Navel gazing on coding style? Pin
Juan Pablo Reyes Altamirano19-Sep-22 6:39
Juan Pablo Reyes Altamirano19-Sep-22 6:39 
AnswerRe: Navel gazing on coding style? Pin
Micha Berger19-Sep-22 7:14
Micha Berger19-Sep-22 7:14 
RantI thought I knew C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch17-Sep-22 14:57
mvahoney the codewitch17-Sep-22 14:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.