
Notes on Data Structures and Programming Techniques - aportnoy
http://cs.yale.edu/homes/aspnes/classes/223/notes.html
======
coldcode
Is teaching people data structures and programming techniques in C really
useful today? Yes I know C is used in many things still and in Linux. But
there is far more variety in what people are paying programmers to use these
days, most of them OO or Functional in nature, neither of which C is. Maybe
there is no other common denominator language one could use that is more
generally applicable? If you ignore Objective-C I haven't used plain C for
anything at all since 1999 even though I used it for more than a decade from
the mid 80's on as my only language.

~~~
megaman22
I don't know of a better way to teach people how pointers work, and all the
other low-level details that higher-level languages gloss over. Day to day, I
agree, you're probably not going to want to be fiddling raw pointers unless
you have to, but for pedadogic purposes, it's worth knowing. Particularly with
so many languages building on C and C-isms.

~~~
saghm
> "I don't know of a better way to teach people how pointers work, and all the
> other low-level details that higher-level languages gloss over"

I definitely agree, but I'm not sure that a data structures/algorithms course
is the best place to be teaching that. I don't know anything about Yale's CS
curriculum, but I'd hope there's at least one systems programming course in
there.

------
abhimt
DSA problem set: [http://www.techiedelight.com/list-of-
problems/](http://www.techiedelight.com/list-of-problems/)

------
rosstex
UC Berkeley's class:
[http://datastructur.es/sp17/](http://datastructur.es/sp17/)

~~~
QML
This semester's:
[http://inst.eecs.berkeley.edu/~cs61b/fa17/](http://inst.eecs.berkeley.edu/~cs61b/fa17/)

Like to mention this is with Java, and not C.

------
hal9000xp
I've been pure C developer for 5+ years (worked with codebase of ~2.5 million
lines of code) and I took a quick look (just out of curiosity) at the content
and one thing immediately strikes me:

[http://cs.yale.edu/homes/aspnes/classes/223/notes.html#What....](http://cs.yale.edu/homes/aspnes/classes/223/notes.html#What.27s_wrong_with_C)

 _7.1 What 's wrong with C_

a) _C doesn 't have a garbage collector_

Disagree that's it's wrong. If you code is well structured, then it's no big
problem to avoid memory leaks. On top of that, you can use RAII if you are
willing to use C-extensions like this one:

[https://lwn.net/Articles/589433/](https://lwn.net/Articles/589433/)

Garbage collector just helps you to write _semi-workable_ messy code (a dream
of industrial developers).

b) _C doesn 't support any kind of polymorphism_

If you use type cast in well structured code, it's no big problem.

c) _C doesn 't have exceptions_

This may be a bit tricky but you still can use exceptions in C using _longjmp
/setjmp_:

[http://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.ht...](http://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.html)

Although ___cleanup___ extension doesn't work in this case.

It's worth to take a look at this stack unwinding library:

[http://www.nongnu.org/libunwind/](http://www.nongnu.org/libunwind/)

Quote:

 _With libunwind, it is possible to implement an extremely efficient version
of setjmp(). Effectively, the only context that needs to be saved consists of
the stack-pointer(s)._

In general, if you look at _C as a high level assembler_ and willing to write
or use existing low-level framework for "meta-language" primitives (like
pointer virtualization), then you can write nice programs in your "meta-
language".

For example, I wrote some project for fun using pure C with bare minimum
libraries. And I needed to make sure that I could detect the following bug as
soon as possible:

1\. Object _X_ is created and owned by some code _OWNER_X_ ;

2\. Pointer to this object _X_ is passed to some code _USER_OF_X_ ;

3\. Object _X_ is freed in _OWNER_X_ ;

4\. New object _Y_ is created in _OWNER_X_ which happens to have the same
address as recently freed object _X_ ;

5\. Because of some bug _USER_OF_X_ still uses pointer to object _X_ ;

I wanted _USER_OF_X_ to fail on asserts as soon as possible if this happens.
It would be hasty bug and hard to detect in unprepared code if _X_ and _Y_
happens to be the same type. When people are saying that it's nearly
impossible to detect such bugs in C, they just don't consider using framework
which cleverly detects this issue.

By the way, this is my implementation pointer virtualization which helps to
detect this sorts of bugs:

[https://github.com/hal9000xp/euclid/blob/master/core/main.h](https://github.com/hal9000xp/euclid/blob/master/core/main.h)

Look at _PTRID_.

[https://github.com/hal9000xp/euclid/blob/master/core/linked_...](https://github.com/hal9000xp/euclid/blob/master/core/linked_list.h)

Look at usage of _PTRID_ in _LL_CHECK_

This is how I use them together:

[https://github.com/hal9000xp/euclid/blob/master/core/network...](https://github.com/hal9000xp/euclid/blob/master/core/network.c)

~~~
xapata
When do these frameworks become language extensions? There are always caveats
to assertions about language features.

------
abhas9
I read the Dynamic Programming section & I must say that it is very well
explained.

Found a small issue. In Binary search section, it says ```{.c
include=examples/binarySearch/binarySearch.h}```

Instead of the original code. I guess the page generator messed up a little.

~~~
Normal_gaussian
Its messed up in a few places; the vim command descriptions for example.

------
sigttin
Anyone know about a similar tutorial that's based around Rust?

------
plg
good grief can we not have even a rudimentary CSS file to make this look at
least a little bit readable?

~~~
falcolas
I prefer this. It’s perfectly readable, scalable, and in the worst case I can
apply my own styling.

I’m on an iPad, fwiw. Ironically one that usually gets some of the worst
styling due to someone else’s opinion of readable.

------
megaman22
This looks like the class I was hoping to get when I took algorithms and data
structures, rather than a semester of CLRS being scrawled on the blackboard
every lecture, mountains of proofs, and 0 lines of code.

~~~
opportune
Not that you are wrong for you opinion, but I feel differently. My data
structures class was all programming, essentially just the professor writing
code on the board for a linked list / trie / etc. after briefly describing it
conceptually, and then having to implement the data structure and perhaps
solve a problem with it for homework. My algorithms classes were all proof
based / theoretical (the most applied problems asking you to come up with a
"novel" algorithm to solve something, but still written). I felt cheated out
of an actual class once I realized my data structures class could have been
designed the same way. Coding the algorithms is usually the trivially boring
or frustrating part to me; it's the actual design or concepts that I enjoyed.

~~~
hackpert
Couldn't agree more. The data structures class I'm taking currently (which is
unfortunately a prerequisite for most other CS classes) is simply a bunch of
trivial programming exercises that take almost no effort to do. While I
understand that everyone has different preferences and is at different levels
of comfort with the concepts, I feel that a proof-based class would be much
more fun.

~~~
andai
Sounds like universities would benefit from having separate "learning tracks"
for students of varying ability like in many high schools.

Or more realistically, taking a more layered approach to each course. So you
could have the basic "code algorithm X to pass the tests" level (the kind of
work most people will be doing later anyway), and then the "let's prove
properties of X / come up with an alternative with the same properties" for
people who can pass the first part in their sleep.

The best courses I've taken work like that already, plenty of extra challenges
if you finish early. But it takes a dedicated instructor to make it work, and
most of them unfortunately seem dedicated to getting by with minimum effort.

------
codemac
What software did they use to generate this page? My first guess was org-mode,
but it doesn't look like that. Maybe markdown + pandoc?

~~~
codemac
Ooop yep, pandoc. Don't know what the source format was yet though.

    
    
        <meta name="generator" content="pandoc" />

