|
|
|
|
|
by matvore
2273 days ago
|
|
> it takes a crazy amount of effort
I agree with basically everything you've said but I don't buy that it takes a crazy amount of effort to do anything. You have C. If it's hard to do in C, you have a Makefile. If it's hard to do with a Makefile, you can run a script during the build process. Anything can be streamlined. > it's also possible to have dependency injection in C by using structs with function
> pointers, but I think we can all agree that it's a lot less pleasant to use than C++
> abstract base classes
I hate function pointers, and void* context pointers even more, so I wrote macros to do binary search and sorting so I didn't have to pass a void* to qsort(3) and bsearch(3) (also, bsearch(3) doesn't tell you the insertion point of a missing element)If you want to sort an array: int arr[] = {5, 10, 15, 17, 20};
size_t size = sizeof(arr) / sizeof(*arr);
QSORT(arr, size, arr[a] < arr[b]);
If you want to find the value 5 in that array: ssize_t index;
BSEARCH_INDEX(index, size, arr[index] - 5);
// Now 'index' has the result.
|
|
The fact that you hate function pointers and void* context pointers is an exact confirmation of my premise: people think it’s too much of a hassle.