Logical Expressions in C/C++. Mistakes Made by Professionals
-
@dse low level and high performance programming is way harder than anything I do day to day. But I do find it somewhat fun to learn about.
I know next to nothing about C, but have been looking into C++ every now and then.
@anotherusername I did phrase poorly, but it looks like a balance is needed in this specific case, as @dse has expressed concerns about both code size and speed.
Your example is somewhat fun because there's a third option, you can calculate the digits of pi individually as they are needed.
-
@anotherusername What if your amount of memory can handle half of those numbers? Contrived example but then you see why speed-vs-size is not exactly inverse. More realistically what if those digits leave small room for the rest of data? You will have to cache different thing, now you made
pi
fast (kind of because you will still need to index it which needs a hidden temporary variable) at the expense of every other function.
-
@dse said in Logical Expressions in C/C++. Mistakes Made by Professionals:
need to index it which needs a hidden temporary variable
What? why? indexing an array in C isn't just taking the address of first item + offset? the compiler should be able to just throw the right value at the current working register.
Here I understand that you mean that another memory location is needed to store the array element before you can work with it.
-
@Sentenryu said in Logical Expressions in C/C++. Mistakes Made by Professionals:
you can calculate the digits of pi individually as they are needed.
...well, that could possibly save runtime memory, but probably not execution speed.
I was just considering executable size vs. speed. Obviously there are other variables in play; optimization generally is a tradeoff between speed, executable size, and runtime size (memory required).
You guys are overthinking the example, though. It was just the first thing that popped into my head to demonstrate that executable size can sometimes take a backseat to other factors like execution speed.
-
@Sentenryu right, I was thinking of arrays with more than one dimension.
-
@Sentenryu said in Logical Expressions in C/C++. Mistakes Made by Professionals:
What? why? indexing an array in C isn't just taking the address of first item + offset? the compiler should be able to just throw the right value at the current working register.
But if that location is currently not present in physical memory (because it has been paged out by the OS) then your super fast array lookup has just been converted to disk IO. Oops! :D There's a lot of stuff in this area that is really non-obvious because it's related to multiple levels of abstraction at once; you have to measure what stuff actually does, not just guess about it.
-
@dse said in Logical Expressions in C/C++. Mistakes Made by Professionals:
Yes, and without meta-programming they are only marginally more useful than macros.
They are way less error-prone.
Also, I disagree: Template metaprogramming might be weird, but these days you can hardly call it an abuse of templates, since it's so incredibly widespread and is exactly what makes templates more powerful than their counterpart in any other language. Once you get used to the patterns, it isn't hard to understand, either.
-
@asdf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
Once you get used to the patterns, it isn't hard to understand, either.
Highly recommended if you think template metaprogramming is black magic:
https://www.youtube.com/watch?v=Am2is2QCvxY
https://www.youtube.com/watch?v=a0FliKwcwXE
-
@asdf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
more powerful than their counterpart in any other language
Be careful of that claim, as you'll end up getting a run in with the Lisp folks, who will look at what C++ does and scoff. :)
-
@dse Arrays with more than one dimension are still one contiguous address range in memory, maybe with jagged arrays allocated on the heap?
@dkf You do raise a good point about paging. Low level performance is hard stuff, that might be why I like to pretend I'm learning C++ even if I'll never really use it on a project.
Edit: Double posted due to cooties, removed the second post.
-
This post is deleted!
-
@Sentenryu said in Logical Expressions in C/C++. Mistakes Made by Professionals:
Low level performance is hard stuff
It's simple enough. Don't guess. Measure it, and measure it on as real an example as possible.
Though it helps to pick the right algorithm to start with. ;)
-
@dkf I can't help but feel like only measuring leads one to the "works in my machine" scenario.
But then again, there's nothing better that can be done anyway.
-
@asdf That guy looks so boring I'm falling asleep to his YouTube preview images.
Also generally, maybe I'm crazy, but generally you'd position the camera so that he's facing it. https://www.youtube.com/watch?v=GEi4Os3NNpM
-
@asdf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
Highly recommended if you think template metaprogramming is black magic:
The problem isn't that it's black magic. What it tries to do is simple to understand, but the syntax is terrible.
-
@blakeyrat said in Logical Expressions in C/C++. Mistakes Made by Professionals:
That guy looks so boring I'm falling asleep to his YouTube preview images.
His speaking style annoys the heck out of me, and he's not one for delivering snappily either. Two videos of about an hour each, and the content could be grasped in 5 minutes of reading something focused.
-
@Sentenryu said in Logical Expressions in C/C++. Mistakes Made by Professionals:
I can't help but feel like only measuring leads one to the "works in my machine" scenario.
Sometimes, but usually not. Most performance differences are usually consistent (or consistent enough anyway) and there are tools that let you measure that last few percent. (Cachegrind is not for beginners, but it's capable of telling you which part of your code is actually slow. Assuming it's not straight memory- or I/O-bound, but those are easier scenarios to get a hunch for.)
-
Two videos of about an hour each, and the content could be grasped in 5 minutes of reading something focused.
That's true for 90% of all conference talks ever.
-
@asdf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
That's true for 90% of all conference talks ever.
Most conference talks take 10 minutes of content and spread it over 20–30 minutes. NOT TWO HOURS!
-
@dkf To be fair, he didn't only explain the concept, but shared quite a few examples in those two hours. Also, at least 20 minutes were Q&A.
-
@asdf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
at least 20 minutes were Q&A.
and at least 10 minutes were “I'm more of a greybeard than you young whippersnappers ”
It could have been condensed.
-
@dkf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
It could have been condensed.
Now that is true for 100% of all conference talks ever.
If you have a better video, feel free to post it. I know it's a bit long, but it's the best introduction to the topic I've seen so far.
-
@dkf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
and at least 10 minutes were “I'm more of a greybeard than you young whippersnappers ”
so, you took offense with that?
-
@Sentenryu With it being true? No. With him rambling on about it? Yes.
-
@dkf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
It could have been condensed.
I can still read much faster than I can listen. Video has its place, but in this context, it's mostly used to shift the burden to the viewer; easier to produce, but harder to consume. I'm happy there's more content, but I would prefer text to videos.
-
@Jaime said in Logical Expressions in C/C++. Mistakes Made by Professionals:
easier to produce
Not really. Slapping the slides online is even easier, and so is not bothering making the talk/slides in the first place.
-
@dkf said in Logical Expressions in C/C++. Mistakes Made by Professionals:
Most conference talks take 10 minutes of content and spread it over 20–30 minutes. NOT TWO HOURS!
Ah, but that is why you submit your talks as quarter or half-day courses.
-
@cvi Fuck that shit. I really can't be assed to produce that much content.