Earlier quoted context omitted.
Because not everyone who reads HN went through a CS program, and may have not seen implementations of common data structures like this before. Its a well-written tutorial that conveys the topic well.
My advice would be to take this to another website, one specifically for introductory CS topics. I expect a higher level of discussion on HN.
Write a hash table in C
11–20 of 58 posts
Re: Write a hash table in C
#12While the reasons for this that the author gave are valid, I think it would also be valuable to do this in a high level language. I'm sure lot of people who can read C code went through a CS program, and hopefully learned how hash tables work then. People without CS degrees and who mostly write JS/Ruby/Python/etc. and use hash tables on almost every line of code they write are much less likely to know how they work.…
The hard part is allocation memory, keeping track of the structure(array) holding the hashtable, etc.
What else is there? Implementing the hash function/code?
If you don't have a CS degree, you probably don't even know how lists, queues, stacks, etc really work. But the kind of programming that is done at a "high" level, you might not even need know it.
Instead of saying people should implement it JS/Ruby/Python/etc ( all of whom are OOPs ), they should learn C and implement it in C.
Re: Write a hash table in C
#13Earlier quoted context omitted.
Because not everyone who reads HN went through a CS program, and may have not seen implementations of common data structures like this before. Its a well-written tutorial that conveys the topic well.
My advice would be to take this to another website, one specifically for introductory CS topics. I expect a higher level of discussion on HN.
Re: Write a hash table in C
#14Re: Write a hash table in C
#15Re: Write a hash table in C
#16While the reasons for this that the author gave are valid, I think it would also be valuable to do this in a high level language. I'm sure lot of people who can read C code went through a CS program, and hopefully learned how hash tables work then. People without CS degrees and who mostly write JS/Ruby/Python/etc. and use hash tables on almost every line of code they write are much less likely to know how they work.…
The problem with writing hash tables or any fundamental data structures in JS/Ruby/Python/etc is that most of the hard work is done for them. The hard part is allocation memory, keeping track of the structure(array) holding the hashtable, etc. What else is there? Implementing the hash function/code? If you don't have a CS degree, you probably don't even know how lists, queues, stacks, etc really work. But the kind of…
Not having to deal with boilerplate and housekeeping lets you focus on learning the topic at hand. Especially in a classroom setting where you're probably focusing on the specific subject instead of real-world dirtiness.
But after learning the basic concept, you do need an actual implementation if you want to do anything.
Re: Write a hash table in C
#17Hashtables are one of those data structures one can easily get away with never having to write on their own, yet still use every day. In scripting languages it's impractical to roll your own, & in the more abstracted low level languages there'll usually be a pretty good generic version. Yet there's much room for variation
I had the joy to be out of reach of off-the-shelf hashtables for luwa,
init: https://github.com/serprex/luwa/blob/436c7271120fcd116af30e9...
get/set: https://github.com/serprex/luwa/blob/436c7271120fcd116af30e9...
hash: https://github.com/serprex/luwa/blob/436c7271120fcd116af30e9...
Still need to implement Lua's sequential-portion-as-array logic. I do like the API not having a 'remove' method, opting intead for nil by default. nil value entries get vacuumed out when rehashing. This ends up acting as tombstone. In an earlier iteration I was using 0 as a marker distinct from nil, but an implementation detail is that nil is stored at address 0.. oops
Re: Write a hash table in C
#18Earlier quoted context omitted.
The problem with writing hash tables or any fundamental data structures in JS/Ruby/Python/etc is that most of the hard work is done for them. The hard part is allocation memory, keeping track of the structure(array) holding the hashtable, etc. What else is there? Implementing the hash function/code? If you don't have a CS degree, you probably don't even know how lists, queues, stacks, etc really work. But the kind of…
There's room for both. There's a reason why a lot of CS programs have shuffled from primarily C to Python (some had Java in between). Not having to deal with boilerplate and housekeeping lets you focus on learning the topic at hand. Especially in a classroom setting where you're probably focusing on the specific subject instead of real-world dirtiness. But after learning the basic concept, you do need an actual imple…
Sure. I'm all for learning ML, Scheme, C/C++, Python, Ruby, Java/C#, etc.
> There's a reason why a lot of CS programs have shuffled from primarily C to Python (some had Java in between).
The reason is called dumbing down the curriculum. My fall freshman year, my college tried to switch from C to Java in order to make it easier for the general population to get into CS and there was a major pushback from the CS student body, alumni and a bunch of the CS professors. We went back to C/C++ my sophomore year.
> Not having to deal with boilerplate and housekeeping lets you focus on learning the topic at hand.
I disagree. Having to deal with the boilerplate and housekeeping helps you learn the topic at hand.
> But after learning the basic concept, you do need an actual implementation if you want to do anything.
I disagree. Giving them "training wheels" will keep them dependent on training wheels. In an idealistic world, people go from Java/Python to C/Assembly, but that's rarely the case.
CS should begin with Math ( boolean algebra/logic/etc ), Assembly and C. Then go on to functional paradigms. Then to OOP. Etc ( in the language ). Of course they should also learn about OS( kernel/filesystems/etc ), networks, computation theory/etc, compilers, etc.
The dumbing down of the curriculum so that music/english majors can pass CS classes doesn't do anyone any favors.
Re: Write a hash table in C
#19Re: Write a hash table in C
#20The standard library does come with a half-baked hash table implementation[1] (hcreate/hdestroy/hsearch) that only allows creation of _one_ global hash table. GNU libc[2] adds hcreate_r/hdestroy_r/hsearch_r that allows multiple tables to be created.
The APIs are strange and antiquated. On the other hand, the hash table implementation described in the article presents a much nicer interface.
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/hcr...