Pointers are the coolest thing yet in c++

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 3246 Views - Last Post: 11 December 2017 - 10:30 AM

#16 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5928
  • View blog
  • Posts: 20,271
  • Joined: 05-May 12

Re: Pointers are the coolest thing yet in c++

Posted 26 October 2016 - 06:36 AM

I've got the impression that dandymcgee works I the game industry or in another graphics intensive field. Often, the low level APIs on these systems assume assume C or assembly callers for minimal overhead. And it often involves pointer to raw buffers. Unfortunately, this concept can easily bubble up into whatever framework or game engine, much like how it is easy to have a database concept or data transfer object bubble up into a object oriented 3 tier or MVC application.

Don't believe me that DB concepts leak into an object oriented app: recall when you learned data structures and simply had references to nodes in a list, tree, or heap. Notice that all you needed were the references. Now go to most tutorials about how read in data from a relational database into a list, tree or heap, and then later write updates back out again. More often than not, the row ids bubble up all the way into the data structure instead of a mapping layer that strips away the id.

If I recall correctly, there were a few articles in Game Programming Gems regarding using STL in games, but retaining performance. Alas, they did involve doing some specializations and using pointers under the covers. The takeaway, though was to let the devs focus on higher level concepts and abstract away the pointers.
Was This Post Helpful? 1
  • +
  • -

#17 dandymcgee  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 12
  • Joined: 12-October 16

Re: Pointers are the coolest thing yet in c++

Posted 26 October 2016 - 07:29 AM

** Note: More opinion and personal experience below. Take it for what it is. **
I should probably add that ^ as a disclaimer in my signature, because nothing I say should be taken a blanket truth. Also, I appreciate the respectful debate, even when they completely disagree with me, so by all means rip this one apart if you have something to add.
**

View PostSkydiver, on 26 October 2016 - 06:36 AM, said:

I've got the impression that dandymcgee works I the game industry or in another graphics intensive field. Often, the low level APIs on these systems assume assume C or assembly callers for minimal overhead. And it often involves pointer to raw buffers. Unfortunately, this concept can easily bubble up into whatever framework or game engine, much like how it is easy to have a database concept or data transfer object bubble up into a object oriented 3 tier or MVC application.


Absolutely, yes. My current interests are fairly low-level: kernel development, rendering engines, GPGPU. I've been known to say I'm of the breed that prefers to make Unity than make a game in Unity.

To be clear, abstractions are not a bad thing. Rather, I've never liked using them without understanding how they work, and I *hate* black box abstractions. Any reasonably sized project is going to require you to develop some level abstraction for one thing or another, but it's different when you have the power to change the internals when they don't perform to your expectations vs. having to blame someone else for your performance problems (I've had to do this in the industry, and I hate telling consumers that my product is slow because of some pre-compiled library I'm *required* to use; it's embarrassing, honestly).

At the end of the day, our job as programmers is to meet the project requirements. In some cases, that includes bare metal performance, in most cases, it does not. Use the tool that is right for the job. If you can meet your goals with 100% references in C++ and have absolutely no need for pointers, then don't use them! Just be careful about advocating that as the "superior in all cases" approach, because it's not.

It has been said before that the best approach to programming is writing the dumbest possible implementation of everything, then profiling, and improving the parts that work least well. While I understand the sentiment, that's totally ridiculous in reality. When you've been programming for 5, 10, 30 years, whatever, you can reasonably predict ahead of time that certain choices will make for a drastically better product, and you can save yourself a lot of time by just writing it as best as you know how to begin with.
Was This Post Helpful? 1
  • +
  • -

#18 jimblumberg  Icon User is offline

  • member icon

Reputation: 5344
  • View blog
  • Posts: 16,679
  • Joined: 25-December 09

Re: Pointers are the coolest thing yet in c++

Posted 26 October 2016 - 08:42 AM

Quote

If you can meet your goals with 100% references in C++ and have absolutely no need for pointers, then don't use them! Just be careful about advocating that as the "superior in all cases" approach, because it's not.

No one here has said any particular method is "superior in all cases". It has been said to avoid pointers whenever possible in C++, which is a good practice in C++. However "whenever possible" doesn't mean always. Pointers do have their uses and in some cases can't be avoided, nor should they be totally ignored. However always using pointers when other methods are available is risky.

Quote

When you've been programming for 5, 10, 30 years, whatever, you can reasonably predict ahead of time that certain choices will make for a drastically better product, and you can save yourself a lot of time by just writing it as best as you know how to begin with.

This is only true if you are keeping abreast of the changing language. Many people who have been programming for years are very reluctant to alter their way of thinking and as time wears on they have become so set in their ways that their way is the only way. No new enhancement of the language will ever be as good as "my way" so why bother looking into the language enhancements.

Quote

My current interests are fairly low-level: kernel development, rendering engines, GPGPU. I've been known to say I'm of the breed that prefers to make Unity than make a game in Unity.


If you're doing kernel development you will probably not have all the bells and whistles available to most non-kernel developers since kernel development is usually considered a non-hosted environment and need not supply everything required by hosted environments. So in this case your C++ will probably be closer to C than C++, no or very limited streams, no or very limited STL, specialized memory allocators, etc.

Quote

Any reasonably sized project is going to require you to develop some level abstraction for one thing or another, but it's different when you have the power to change the internals when they don't perform to your expectations vs. having to blame someone else for your performance problems

This sounds like you prefer to work alone, or on your own projects, and would rather not be burdened by being a team player using team approaches or team methods. After all unless you're the person setting the goals, requirements you will probably not have control of the parts of the code base being developed by the other team members. You also seem to think that performance is the only, or at least the major, goal of all projects. While performance is important to all programs it really should not be the primary requirement to any program, IMO. In reality the primary goals should be to create a program that is clear and clean (understandable), reliable, efficient, and modular in a timely fashion. That last item can and usually does lead to compromises to all of the preceding points. And note efficient is present but not the top goal.

Jim
Was This Post Helpful? 1
  • +
  • -

#19 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10734
  • View blog
  • Posts: 18,362
  • Joined: 19-March 11

Re: Pointers are the coolest thing yet in c++

Posted 26 October 2016 - 08:53 AM

Quote

I *hate* black box abstractions


Can you expand on this? This seems like a sentiment that most programmers go through, but you sound like you've been in the field for a while, so you've probably put more thought into it than the average CS sophomore.
Was This Post Helpful? 0
  • +
  • -

#20 dandymcgee  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 12
  • Joined: 12-October 16

Re: Pointers are the coolest thing yet in c++

Posted 26 October 2016 - 11:41 AM

View Postjimblumberg, on 26 October 2016 - 08:42 AM, said:

This sounds like you prefer to work alone, or on your own projects, and would rather not be burdened by being a team player using team approaches or team methods. After all unless you're the person setting the goals, requirements you will probably not have control of the parts of the code base being developed by the other team members.

To the contrary, I really enjoy working with teams. What I don't enjoy is depending on external code maintained by a party who 1) for one reason or another can't receive change requests *and* 2) which I do not have rights to improve myself. Legacy code occasionally falls under this category due to time constraints, but if our company owns it I *can* improve it if I must. The much bigger cause of pain is using third-party libraries developed by companies who simply have no interest in my feedback or bug reports.

I work in quite a nice team environment where people can report bugs and performance requests to me, and I will implement them if they make sense. Vice versa, if I request a sensible fix on their end, it will more often than not be honored. I will happily give up maintaining some portion of a project to someone else who handles it responsibly. For some projects the STD library meets these qualifications, for others it might not.

View Postjimblumberg, on 26 October 2016 - 08:42 AM, said:

You also seem to think that performance is the only, or at least the major, goal of all projects. While performance is important to all programs it really should not be the primary requirement to any program, IMO. In reality the primary goals should be to create a program that is clear and clean (understandable), reliable, efficient, and modular in a timely fashion. That last item can and usually does lead to compromises to all of the preceding points. And note efficient is present but not the top goal.


Actually, if you go back and check I said exactly that: "At the end of the day, our job as programmers is to meet the project requirements. In some cases, that includes bare metal performance, in most cases, it does not. Use the tool that is right for the job."

I understand that performance is not always #1, and (as much as I don't like that attitude) sometimes you just have to meet the basic requirements and move on. Especially when development time is your limiting factor. Fact of life.

View Postjon.kiparsky, on 26 October 2016 - 08:53 AM, said:

Quote

I *hate* black box abstractions


Can you expand on this? This seems like a sentiment that most programmers go through, but you sound like you've been in the field for a while, so you've probably put more thought into it than the average CS sophomore.


Sure. I spent a year or so writing a "trouble ticket" tracking application for a managed services provider. The system is used to track various software, resources, support requests, etc. from the customers. Since it was a Windows environment, the application was written in C# with Windows Forms, a great language and environment to get full-featured GUI applications out the door in a timely manner. The application had all sorts of fancy grids, calendars, rich text editors, quick access bars, drag-and-snap tool windows, etc. We used a third-party library which provided this behavior. It was a very popular library which focuses on leading-edge features more so than stability. The maintainers will take bug reports, and even give you credits (e.g. toward the next upgrade) for reporting new bugs, but often they are tagged low priority.

One particular example that sticks out is that this suite of controls contained a spell-checker. Writing a spell-checker from scratch would be a pain in the @$$, so we used it. The spell-checker unfortunately didn't understand apostrophes. E.g. the word "don't" would be interpreted as "don" and "t", both spelled wrong. Now we're stuck with an incredibly deeply-ingrained dependency on a suite of controls that contains a business-interrupting bug that the provider doesn't particularly care about. We can either wait for next version, hope it's fixed, and spend time updating all of the references to the library, re-testing relevant features, etc. or we can write our own spell-checker. Neither option is desirable. What would be most preferable is having a more open library that is easy to customize (preferably via some well-define code interface, rather than just being an open source spaghetti recipe).

There are hundreds of very small issues like this. Users would complain that something wasn't working right, and the option for a fix was waiting 6 months for a new version and doing a major port, or rewriting the functionality from scratch as my own utility library. Generally the answer was, quite unsatisfactorily, "Sorry, it's not my fault, it's XYZ's fault, there's nothing I can do about it." because there are more important things for developers to be doing than rewriting a spell-checker that doesn't understand apostrophes or [insert other minor but impactful issue here].

Writing things from scratch is not always an option, but I would argue that the value of having custom code is directly proportional to the amount of time a code base remains in use. Requirements change. It is much easier to modify something you have direct control over to meet new requirements than it is to port massive code bases to new third-party dependencies.

Moral of the story is, everything in programming is a trade-off.
Was This Post Helpful? 1
  • +
  • -

#21 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10734
  • View blog
  • Posts: 18,362
  • Joined: 19-March 11

Re: Pointers are the coolest thing yet in c++

Posted 26 October 2016 - 02:09 PM

Sorry if I'm not understanding this right, but that doesn't sound like a problem with a black-box abstraction, that's a broken piece of software. Happens, yeah, and yeah it's nice if you can come up with a fix and issue a pull request and get some bragging rights, but the choice to use open software is not what I understood you to be talking about. When I think of "black-box abstractions" I'm thinking of relying on library code. For example, if I'm working in a programming language that offers a library (let's say, something about working with matrices, or indeed the C++ vector library discussed above) I am more concerned with understanding what the library promises and writing code against that contract, and not at all concerned with understanding the choices made by the implementers when they went about providing these goodies.
I might enjoy looking at their code in order to deepen my understanding, or I might investigate if I find a bug, but when I'm wearing my "I'm getting paid for this" hat, I very much like black box abstractions - I want my abstractions to be very tight and solid so that I never have to think about the details of the implementation.
Was This Post Helpful? 1
  • +
  • -

#22 dandymcgee  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 12
  • Joined: 12-October 16

Re: Pointers are the coolest thing yet in c++

Posted 26 October 2016 - 07:39 PM

View Postjon.kiparsky, on 26 October 2016 - 02:09 PM, said:

[...] when I'm wearing my "I'm getting paid for this" hat, I very much like black box abstractions - I want my abstractions to be very tight and solid so that I never have to think about the details of the implementation.

In a perfect world... if only. :)
Was This Post Helpful? 0
  • +
  • -

#23 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10734
  • View blog
  • Posts: 18,362
  • Joined: 19-March 11

Re: Pointers are the coolest thing yet in c++

Posted 26 October 2016 - 09:12 PM

Well, to be fair, even in this very-less-than-perfect world I still prefer my abstractions as tight as possible. And usually if I find that I'm thinking more than very occasionally about the implementation and not the contract, I start looking for another way to get that job done, because the tool I'm using is not a good one.
Was This Post Helpful? 0
  • +
  • -

#24 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon


Reputation: 6997
  • View blog
  • Posts: 14,636
  • Joined: 16-October 07

Re: Pointers are the coolest thing yet in c++

Posted 27 October 2016 - 04:35 AM

View Postdandymcgee, on 26 October 2016 - 01:41 PM, said:

Writing things from scratch is not always an option, but I would argue that the value of having custom code is directly proportional to the amount of time a code base remains in use. Requirements change. It is much easier to modify something you have direct control over to meet new requirements than it is to port massive code bases to new third-party dependencies.


I agree. Broken toys you have no control over is a problem. I've also run into this issue and also tend to avoid proprietary stuff. However, you seem to be making a reasonable case for open source than a not invented here mentality.

When I choose to leverage a third part code base, I lean toward stuff I can patch myself, which means being able to see source, if needed. Indeed, for any new project I tend to spend some time surveying the state of available tools, with an eye toward stability, support, and open source, as well as applicability. I often do have to write it myself, but the effort of looking never feels wasted and often inspires what I ultimately do come up with.
Was This Post Helpful? 0
  • +
  • -

#25 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5928
  • View blog
  • Posts: 20,271
  • Joined: 05-May 12

Re: Pointers are the coolest thing yet in c++

Posted 29 October 2016 - 09:12 PM

And to bring us back on topic...

View Postjeffindenver, on 24 October 2016 - 04:15 PM, said:

So what's the story with these? Are they primarily used in writing compilers and system software?


As noted in post #3 by baavgai:

View Postbaavgai, on 24 October 2016 - 07:53 PM, said:

C++ isn't quite a standalone language; it stands on the shoulders of C.


C is a step up above the bare metal work of using assembly. Most modern processors have the concept of indirection as an addressing mode. This is what pointers essentially translate to.
Was This Post Helpful? 1
  • +
  • -

#26 dandymcgee  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 12
  • Joined: 12-October 16

Re: Pointers are the coolest thing yet in c++

Posted 06 February 2017 - 07:42 AM

View Postbenhart, on 06 February 2017 - 03:04 AM, said:

Pointers can be very helpful when you seek to pass information between different modules but it's also a bit of a trap because you have to delete them all and it's sometimes can be difficult to detect where exactly to do that.

This is misleading. You don't have to delete pointers, you have to delete all memory which was allocated on the heap with new. Pointers can point to *anything*, not just dynamically allocated memory. Even in the case of dynamically allocated memory on the heap, you aren't deleting the pointer itself but rather the block of memory it points to.
Was This Post Helpful? 3
  • +
  • -

#27 §ingulαrity  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 30-July 14

Re: Pointers are the coolest thing yet in c++

Posted 29 August 2017 - 01:28 AM

Understanding the reasons to use pointers, references, etc seems to come down to understanding the fundamental concepts of how memory is handled by your platform. Profiling can be very enlightening in this regard, but more than that, how you structure a program that's going to handle large amounts of data should be largely influenced by how that data is represented in memory. In the cases of high-level abstracted systems, you may not need to understand what's going on behind the scenes, but even then, should the volume of data be more than a little logic, it can be incredibly beneficial to understand what is happening at a lower level.
It's easy to miss a small detail that can tank performance when using a lot of abstract objects, and profiling can certainly help with that, but these abstractions can make such results especially confusing.
Don't get me wrong, I don't mean to say abstractions are a bad thing or that everything should be written in low-level code, but it's important to understand how to use these abstractions properly, without too much extra work going on behind the scenes. Overhead can add up pretty fast.
Perhaps some of that comes from my own curiosity and love for tinkering, but I wholly believe that a lot of projects would benefit from some more careful foresight (and a lot more Data-Oriented Design).
Was This Post Helpful? 0
  • +
  • -

#28 Emilycarl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-November 17

Re: Pointers are the coolest thing yet in c++

Posted 11 December 2017 - 10:30 AM

#11 Skydiver its nice you have to describe C background before going to C++ actually C++ have many efficient ways to editing make programming and the advance thing is pointers that really helpful actually for me while I was making assignment on C++. But its slow so Its good advice to start with C before going to C++.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2