From joe at begriffs.com Sun Apr 25 23:08:18 2021 From: joe at begriffs.com (Joe Nelson) Date: Sun, 25 Apr 2021 18:08:18 -0500 Subject: Code review for new library Message-ID: <20210425230818.GA58932@begriffs.com> Hey all, can I get a code review on my new project? https://github.com/begriffs/libderp Backstory: I was working on some parser examples, and for one of the programs I needed an associative map. I got mad that there wasn't a library for this that worked to my liking. So I took a detour to make (yet another) C collection library, but one that's easy to build and avoids tricky macro magic or "invasive" data structure changes. I haven't added any documentation yet, but thought I'd check how people like the interface first. I tried to get inspiration from these libraries, and find commonality: * C++ STL https://www.cplusplus.com/reference/stl/ * Ada 2012 containers https://www.adaic.org/resources/add_content/standards/12rm/html/RM-TOC.html * Smalltalk collection protocols https://wiki.squeak.org/squeak/uploads/172/standard_v1_9-indexed.pdf * .NET https://docs.microsoft.com/en-us/dotnet/standard/collections/#choose-a-collection * java.util https://docs.oracle.com/javase/7/docs/api/java/util/package-frame.html Also consulted the Standard ML basis library, the Haskell 2010 language report, and Common Lisp HyperSpec. However those functional libraries didn't really apply. So far I've implemented vector (dynamic array), list (doubly linked), and hashmap. Ways you can help: * Is the current interface missing functions that you'd find useful? Going to add a iterator for the hashmap, for one thing... * Are the names meaningful to you? Feel free to bikeshed. * See any bugs? Or even have a hunch of things I should test? * Can we simplify the Makefile in a totally portable way? It's very repetitive. * The algorithms aren't fancy, but do you see obvious improvements? For instance, my mergesort is recursive and could theoretically hit stack limitations. Things along those lines. * Does the project build on your system? * Should the function names have a common prefix? My plan is to rewrite the tests more methodically, using code coverage to guide me in coming up with scenarios. Then write a man page for each function. Then have it compile a .a and .so library. Finally add versioning and pkg-config information, and package it up for a bunch of OSes. Thanks for your help! From nicholasdrozd at gmail.com Thu Apr 29 21:55:26 2021 From: nicholasdrozd at gmail.com (Nicholas Drozd) Date: Thu, 29 Apr 2021 16:55:26 -0500 Subject: Code review for new library In-Reply-To: <20210425230818.GA58932@begriffs.com> References: <20210425230818.GA58932@begriffs.com> Message-ID: This is a very shallow review, but I couldn't get the tests to run. make tests c99 -Iinclude -DNDEBUG -O1 -o build/release/test/t_vector build/release/vector.o test/t_vector.c /usr/bin/ld: cannot open output file build/release/test/t_vector: No such file or directory collect2: error: ld returned 1 exit status make: *** [Makefile:26: build/release/test/t_vector] Error 1 That's after running `make`. On Sun, Apr 25, 2021 at 6:08 PM Joe Nelson wrote: > > Hey all, can I get a code review on my new project? > https://github.com/begriffs/libderp > > Backstory: I was working on some parser examples, and for one of the > programs I needed an associative map. I got mad that there wasn't a > library for this that worked to my liking. So I took a detour to make > (yet another) C collection library, but one that's easy to build and > avoids tricky macro magic or "invasive" data structure changes. > > I haven't added any documentation yet, but thought I'd check how people > like the interface first. I tried to get inspiration from these > libraries, and find commonality: > > * C++ STL https://www.cplusplus.com/reference/stl/ > * Ada 2012 containers https://www.adaic.org/resources/add_content/standards/12rm/html/RM-TOC.html > * Smalltalk collection protocols https://wiki.squeak.org/squeak/uploads/172/standard_v1_9-indexed.pdf > * .NET https://docs.microsoft.com/en-us/dotnet/standard/collections/#choose-a-collection > * java.util https://docs.oracle.com/javase/7/docs/api/java/util/package-frame.html > > Also consulted the Standard ML basis library, the Haskell 2010 language > report, and Common Lisp HyperSpec. However those functional libraries > didn't really apply. > > So far I've implemented vector (dynamic array), list (doubly linked), > and hashmap. > > Ways you can help: > * Is the current interface missing functions that you'd find useful? > Going to add a iterator for the hashmap, for one thing... > * Are the names meaningful to you? Feel free to bikeshed. > * See any bugs? Or even have a hunch of things I should test? > * Can we simplify the Makefile in a totally portable way? It's very > repetitive. > * The algorithms aren't fancy, but do you see obvious improvements? > For instance, my mergesort is recursive and could theoretically > hit stack limitations. Things along those lines. > * Does the project build on your system? > * Should the function names have a common prefix? > > My plan is to rewrite the tests more methodically, using code coverage > to guide me in coming up with scenarios. Then write a man page for each > function. Then have it compile a .a and .so library. Finally add > versioning and pkg-config information, and package it up for a bunch of > OSes. > > Thanks for your help! From joe at begriffs.com Fri Apr 30 02:28:31 2021 From: joe at begriffs.com (Joe Nelson) Date: Thu, 29 Apr 2021 21:28:31 -0500 Subject: Code review for new library In-Reply-To: References: <20210425230818.GA58932@begriffs.com> Message-ID: <20210430022831.GC67903@begriffs.com> > This is a very shallow review, but I couldn't get the tests to run. > > make tests Thanks for trying it out. Looks like I need better documentation. The tests use assert() and the release build sets NDEBUG which disables assertion checking. Try the dev variant instead: make VARIANT=dev tests ./build/dev/test/run (I'm curious if that'll compile for you, since the dev variant uses clang specifically, while the release variant uses whatever your system has assigned to CC.) From martin.vanwinkle at gmail.com Fri Apr 30 21:22:16 2021 From: martin.vanwinkle at gmail.com (Martin VanWinkle) Date: Fri, 30 Apr 2021 17:22:16 -0400 Subject: Code review for new library In-Reply-To: <20210425230818.GA58932@begriffs.com> References: <20210425230818.GA58932@begriffs.com> Message-ID: Joe, Here are the templates that I use for autotools style projects. Man and info pages are under doc, pkgconfig stuff is under lib. Nothing has been reviewed by somebody who has more experience than me, so I'm not sure if I'm doing anything wrong. For example, I'm pretty sure I should be using the TESTS thing that autotools has, instead of always compiling the program to test the library. https://github.com/mvanwinkleias/mv_c_package_template_test/tree/master/src/templates/c_library_template2 Instructions for building debian packages are in ExtraMakefile. I don't have spec file generation done (yet). The templates can be filled out by this project: * https://github.com/theias/ias_package_shell By specifying the project Template dir and control file like this --project-template-dir ... --project-control-file ... (They're in src/templates) (Or, you can edit the templates by hand, or I can generate them for you) It's been a long time since I've done anything serious with C, but I'll definitely give your code a read through. Marty On Sun, Apr 25, 2021, 19:08 Joe Nelson wrote: > Hey all, can I get a code review on my new project? > https://github.com/begriffs/libderp > > Backstory: I was working on some parser examples, and for one of the > programs I needed an associative map. I got mad that there wasn't a > library for this that worked to my liking. So I took a detour to make > (yet another) C collection library, but one that's easy to build and > avoids tricky macro magic or "invasive" data structure changes. > > I haven't added any documentation yet, but thought I'd check how people > like the interface first. I tried to get inspiration from these > libraries, and find commonality: > > * C++ STL https://www.cplusplus.com/reference/stl/ > * Ada 2012 containers > https://www.adaic.org/resources/add_content/standards/12rm/html/RM-TOC.html > * Smalltalk collection protocols > https://wiki.squeak.org/squeak/uploads/172/standard_v1_9-indexed.pdf > * .NET > https://docs.microsoft.com/en-us/dotnet/standard/collections/#choose-a-collection > * java.util > https://docs.oracle.com/javase/7/docs/api/java/util/package-frame.html > > Also consulted the Standard ML basis library, the Haskell 2010 language > report, and Common Lisp HyperSpec. However those functional libraries > didn't really apply. > > So far I've implemented vector (dynamic array), list (doubly linked), > and hashmap. > > Ways you can help: > * Is the current interface missing functions that you'd find useful? > Going to add a iterator for the hashmap, for one thing... > * Are the names meaningful to you? Feel free to bikeshed. > * See any bugs? Or even have a hunch of things I should test? > * Can we simplify the Makefile in a totally portable way? It's very > repetitive. > * The algorithms aren't fancy, but do you see obvious improvements? > For instance, my mergesort is recursive and could theoretically > hit stack limitations. Things along those lines. > * Does the project build on your system? > * Should the function names have a common prefix? > > My plan is to rewrite the tests more methodically, using code coverage > to guide me in coming up with scenarios. Then write a man page for each > function. Then have it compile a .a and .so library. Finally add > versioning and pkg-config information, and package it up for a bunch of > OSes. > > Thanks for your help! > -------------- next part -------------- An HTML attachment was scrubbed... URL: