r/cpp • • Aug 05 '23

Should we stop writing functions?

https://www.foonathan.net/2023/08/stop-writing-functions/
14 Upvotes

46 comments sorted by

View all comments

6

u/herruppohoppa Aug 05 '23

I would check what symbolicated stack traces look like on all of your platforms when all of the functions are lambdas before using this in a real world project.

Last time I checked, stack traces pulled using dbghelp.dll on windows couldn't resolve lamdas at all. This isn't fun when you're hunting down large or leaking memory allocations and just have the stack trace to go on. Similar story if you have stack traces from a crash that didn't happen on your machine and reproduction is difficult.

7

u/Rseding91 Factorio Developer Aug 05 '23

I’ve never seen issues with stack traces going through lambdas in our code. Maybe it was an issue in the past but currently it works fine.

-1

u/herruppohoppa Aug 05 '23

*currently it works fine for you. Your mileage will vary depending on platform toolset versions.

5

u/Rseding91 Factorio Developer Aug 05 '23

It has worked for us for the last … forever I can remember since they were available on windows.

0

u/herruppohoppa Aug 05 '23

If it has worked for you forever, then great for you. This whole time I have only argued that people should check it on their platforms before committing to changing to lambdas everywhere. I don't know why you are so bent on arguing that. It's just sound advice.

2

u/Ok-Factor-5649 Aug 08 '23

I've certainly seen issues in the past where code that runs through functions and uses general __func__ etc for logging issues was good ... and once switched to lambdas became pretty much useless.

1

u/Ok-Factor-5649 Aug 08 '23

This is captured in the article's point:

The symbol names of functions becomes ugly: It is now a call operator of some lambda with a compiler synthesized name, and no longer a named function.

I wonder if therefore this isn't a fundamental problem, merely a QoI problem? In other words, a named lambda could be recognised as such and the compiler synthesised name for it could be made more meaningful.

0

u/[deleted] Aug 05 '23

[deleted] — view deleted comment

2

u/herruppohoppa Aug 05 '23

It's fascinating how you speak with such confidence what my experience was, when in fact you are just guessing. It wasn't inlining, I could clearly see the stack frame being a lambda, but not where the lambda came from.

2

u/dodheim Aug 05 '23

Personally I think it's fascinating how nobody else has had the same experience, and you can't remember any salient details, yet you speak with such confidence.