4959

Code directory structure - Library design

Question:

below is the code structure, where stack, Queue, tree folder code rely on list folder code,

../Computing >ls HashTable list Queue recursion stack tree

list folder duplicated in tree/rootedTree folder unlike recommended approach to include dependent header files, mentioned <a href="https://stackoverflow.com/a/597329/3317808" rel="nofollow">here</a>,

../Computing/tree/rootedTree >ls lcrsImpl.c list main.c multiWalkImpl.c tree.h

<a href="https://github.com/shamhub/Computing/tree/master/7_Tree/Rooted_tree/Rooted_tree_Implementation_c" rel="nofollow">here</a> is the incomplete code for rootedTree folder.

To avoid code duplication of List folder, How to maintain the code structure?

Answer1:

You seem to have the following structure:

whatever/ list/ ... list.h ... queue/ ... <- some files have an #include "list/list.h"; list/ <- duplicate tree/ rootedTree/ ... list/ <- duplicate tree.h <- has an #include "list/list.h"; test.c <- #include "tree.h"

In this code, you first go to the folder where you want to compile things, and then compile them inside the folder:

you@somewhere:~/whatever/tree/rootedTree$ gcc -Wall -I. -g *.c -o test

The paths of the #include statements are relative to where the compiler is invoked from <em>(as long as you include the -I. argument; thanks, @jean-françois-fabre)</em>. So you can very well have the following (non-duplicated) structure:

whatever/ list/ ... list.h ... queue/ ... <- some files have an #include "list/list.h"; no list/ duplicate tree/ rootedTree/ ... tree.h <- has an #include "list/list.h"; no list/ duplicate testTree.c <- #includes "tree/rootedTree/tree.h" and others

and, <strong>from within the <em>whatever</em> folder</strong>, you can write

you@somewhere:~/whatever$ gcc -Wall -I. -g */*.c testTree.c -o testTree

and get an executable to test. Since calling the compiler directly is boring, especially if you only want to compile the parts of the code where you have actually made changes, you generally use some sort of project definition file (<a href="https://www.gnu.org/software/make/manual/make.html" rel="nofollow">Makefile</a>, <a href="http://scons.org/" rel="nofollow">Scons</a>, ...) to handle that for you.

Duplication is bad, and there is (almost) always a way to avoid it.

Recommend

  • Git subtree post hook
  • use images instead of text in webgrid asp mvc
  • Finding number of samples in a .wav header
  • css active on html inside php echo doesn't stay when click is left
  • Stretch a span across a td
  • Webpack-dev-server and isomorphic react-node application
  • How to create a data template dependent on an XML Attribute?
  • Different Datacontext for Command and CommandParameter
  • angular2 http.post() to local json file
  • undefined reference error due to use of static variables [duplicate]
  • Cannot style mat-tab without ::ng-deep and !important
  • How do I recognize a line break with a switch case that evaluates a char in Java?
  • richtextbox to string
  • Best HTML5 structure for a layout where the title/header is outside the article tag
  • How to align an image side by side with a heading element?
  • Formatting a text in a table cell with PHPWord e.g. bold, font, size e.t.c
  • How to use animated gif in Firemonkey?
  • Creating a C++ function that calls other Lua function
  • incomplete type 'struct' error in C
  • Jquery Knockout: ko.computed() vs classic function?
  • Fail:(TESTMODE) Transactions of this market type cannot be processed on this system
  • saving file generated by TCPDF
  • How to view images from protected folder with php?
  • Textfile Structure (tables)
  • Custom Tabgroup Appcelerator
  • iOS: Detect app start via notification press
  • Initializer list vs. initialization method
  • output of program is not same as passed argument
  • vba code to select only visible cells in specific column except heading
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Akka Routing: Reply's send to router ends up as dead letters
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • Buffer size for converting unsigned long to string
  • Hits per day in Google Big Query
  • How to get Windows thread pool to call class member function?
  • unknown Exception android
  • Checking variable from a different class in C#
  • Busy indicator not showing up in wpf window [duplicate]