Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One of my friends is writing a graphics app using <a href="http://www.nvidia.com/object/cuda_home.html" rel="nofollow noreferrer">NVIDIA CUDA</a>. Application fits in very nicely with OOP paradigm and the problem can be decomposed into modules neatly. However, to use CUDA you need to use C, which doesn't support <a href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)" rel="nofollow noreferrer">inheritance</a>. Therefore, you need to be clever.</p> <p>a) You devise a clever system which will emulate inheritance to a certain extent. It can be done!</p> <p>i) You can use a <a href="http://en.wikipedia.org/wiki/Hooking" rel="nofollow noreferrer">hook system</a>, which expects every child C of parent P to have a certain override for function F. You can make children register their overrides, which will be stored and called when required.</p> <p>ii) You can use struct <a href="http://en.wikipedia.org/wiki/Packed" rel="nofollow noreferrer">memory alignment</a> feature to cast children into parents.</p> <p>This can be neat but it's not easy to come up with future-proof, reliable solution. You will spend lots of time designing the system and there is no guarantee that you won't run into problems half-way through the project. Implementing <a href="http://en.wikipedia.org/wiki/Multiple_inheritance" rel="nofollow noreferrer">multiple inheritance</a> is even harder, if not almost impossible.</p> <p>b) You can use consistent naming policy and use <a href="http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm" rel="nofollow noreferrer">divide and conquer</a> approach to create a program. It won't have any inheritance but because your functions are small, easy-to-understand and consistently formatted you don't need it. The amount of code you need to write goes up, it's very hard to stay focused and not succumb to easy solutions (hacks). However, this ninja way of coding is the C way of coding. Staying in balance between low-level freedom and writing good code. Good way to achieve this is to write prototypes using a functional language. For example, <a href="http://www.haskell.org/" rel="nofollow noreferrer">Haskell</a> is extremely good for prototyping algorithms.</p> <p>I tend towards approach b. I wrote a possible solution using approach a, and I will be honest, it felt very unnatural using that code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload