
Data Structures using C++ - michaelrbock
http://www-scf.usc.edu/~csci102/slides.html
======
dljsjr
My CS degree was 100% C based; Java shows up in a class about OOP, and our
class on Programming Language theory exposes us to Lisp, Java, and Prolog.
They used to be Java based and chose to switch back to a C based curriculum
around 2007, as well as focusing more heavily on algorithms and data
structures while pushing the more "software engineering" type courses in to
elective and offering Software Engineering as a specialization on a CS degree.

Joel Spolsky wrote a great article[1] in 2005 that basically says using a
massively high level language like Python or Java as the core of a CS
curriculum is damaging because the languages aren't "hard" enough. As
curmudgeonly as it might sound, I'd be inclined to agree. Even though I rarely
write C code anymore (we do everything in Java in our lab), the underlying
understanding of memory management that is acquired from having to learn to
handle it manually has been invaluable to me as a programmer.

Additionally, C/C++ is the language of UNIX and still the lingua franca of
high-performance. Most high-level languages worth their salt will have a
foreign interface to dynamically load C libraries; we're in robotics and have
to work heavily with ROS/Gazebo as participants in the DARPA Robotics
Challenge, and even outside of this a lot of really great tools for
mathematical optimization and high-performance numerical analysis are all
written in C. I'm one of only two or three people in our lab with the
requisite knowledge to be able to effectively hand-roll JNI wrappers, and I
don't consider this to be a good thing at all.

It's pretty clear to me that C/C++ aren't going anywhere any time soon, and
it's always good to see a CS curriculum that still focuses on C/C++.

1:
[http://www.joelonsoftware.com/articles/ThePerilsofJavaSchool...](http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html)

~~~
cube13
>Joel Spolsky wrote a great article[1] in 2005 that basically says using a
massively high level language like Python or Java as the core of a CS
curriculum is damaging because the languages aren't "hard" enough. As
curmudgeonly as it might sound, I'd be inclined to agree. Even though I rarely
write C code anymore (we do everything in Java in our lab), the underlying
understanding of memory management that is acquired from having to learn to
handle it manually has been invaluable to me as a programmer.

Python and Java are great starting languages, especially for the first
introductory course. You're really only learning the high level concepts like
basic language syntax(Why are there so many semicolons???), program flow
control(functions, if, for, while statements), working with computer memory
structures, and basic boolean logic. At that point, an easy to understand
language actually makes more sense, because the students are working more with
the concepts than with the language.

After that, when you're teaching data structures, it's important to know how
the memory is allocated and how that can effect your implementation of the
structure. C/C++ are good languages because they force students to deal with
memory allocation and pointers. They also don't have pre-rolled data
structures like python or java, which is important because the goal is to
learn how the structures work, not how to use the standard language libraries.

~~~
plg
My opinion is that one can easily teach these "high level concepts" (loops,
syntax, control flow, etc) using C.

Furthermore my (admittedly curmudgeonly) take on the C vs "high level
languages" debate is that learning something like Python "first" because it's
"easier" is actually sort of damaging, in that the student will learn these
"high level" concepts without any clue about the underlying implementation.
They will then have to learn a bunch of "bag of tricks" that will seem
arbitrary to them, and a bunch of "gotchas" to avoid, again, that will seem
arbitrary to them, because they have no concept of things like the cost of
memory copying (passing-by-value giant arrays as arguments to functions, etc).

I actually think that someone who is incapable or even worse, unwilling to
learn programming using C, has no business programming anything at all of any
import, beyond the most toy-example tiny scripts here and there.

~~~
betterunix
"My opinion is that one can easily teach these "high level concepts" (loops,
syntax, control flow, etc) using C."

Then one day you have a line of students going out the door at your office
hours who all need help understanding why their program is segfaulting. Some
tried to free a pointer to something allocated on the stack, others tried to
free a pointer twice, and one or two managed to find some undefined behavior
that even you did not know about.

It is not that C lacks high-level structures, it is that any non-trivial C
program must deal with low-level issues.

"the student will learn these "high level" concepts without any clue about the
underlying implementation"

That is what computer architecture and compilers courses are for. You learn
more about the implementation of your programs by writing a compiler than you
do by using C, and writing a compiler in a high-level language is almost
always less painful than writing it in C. Somewhere in the compilers course
students should also learn how a garbage collector works, which will help them
understand why they are seeing the behavior they see.

~~~
plg
I disagree : you can easily teach high level concepts like control flow,
branching, loops, logical operations, if/then, without even using pointers.
You can even do some pretty high level numerical algorithm stuff just using
plain old stack variables.

~~~
mahyarm
This is the first exposure to programming & computation class, anything
superfluous such as semicolons or the keywords just trips people up and gets
in the way of learning. You have to tell people to ignore all of the extra
magic words just to get started, even though they would really like to know
what it all means.

Look at Java:

    
    
      public class HelloWorld { 
          public static void main(String[] args) {
              System.out.println("Hello, World");
          }
      }

C:

    
    
      #import <stdio.h>
    
      int main() {
        printf("hello");
        return 0;
      }
    

Python:

    
    
      print "Hello"

~~~
njbooher
#import <stdio.h> -> #include <stdio.h>

------
Peaker
Most C++ implementations of linked lists are bad, including std::list and
apparently, this course's.

People misunderstand linked lists so badly, that they actually list the
motivation for linked lists as fine-grained growth, as opposed to an array-
based list.

The main benefits of linked lists over array-lists are:

* Can put data structures in lists even if they are already in some other data structure. For example, have some ordering between array elements.

* In intrusive style (can find the list links based on the item), can add after that position in O(1).

* In intrusive style with doubly-linked list, can also delete an item in that position in O(1).

Non-intrusive lists are incompatible with having the same O() while also
allowing an item to be in multiple data structures simultaneously.

std::list indeed does not allow this, and is almost useless.

It's sad to see this taught incorrectly in courses, too, perpetuating the
uselessness of std::list.

~~~
zerohp
Your points 2 and 3 are satisfied by using an iterator to keep track of the
position.

~~~
ambrop7
But then you have to pull those iterators into almost everything that deals
with your objects, making the code hard to follow, and wasting memory. The
problem also gets worse when your objects are in more than one list (which you
can't literally do with std::list anyway) since you have to keep several
iterators around.

------
16s
Understanding the C++ std containers is almost a complete lesson in data
structures. std::set is typically a red black tree, std::unordered_set is a
hash table, etc. Looking at how these containers are implemented and
understanding how/when to use which really separates the men from the boys
when it comes to scaling and efficiency.

You can probably learn the concepts from other languages, but it's been my
experience that C++ devs typically understand these concepts more so than
most.

------
appplemac
Uhh that yellow

//

Actually, I'm glad that C++ has been my first programming language. Its syntax
is pretty straightforward, and it's even better to work with when you've got
extremely clear guidelines set up – at my university (UPC BarcelonaTech) we
had a course PRO1, where you got seriously punished if you used spaces instead
of tabs, or if you set 2 as your tabstop, or if you used goto, to name a few.
Now I cannot say that I share all those guideline rules, but at least I
understand what a good C++ code style is.

------
deadfall
Similar:

Stanford - Abstractions and data structures C++

[http://see.stanford.edu/see/lecturelist.aspx?coll=11f4f422-5...](http://see.stanford.edu/see/lecturelist.aspx?coll=11f4f422-5670-4b4c-889c-008262e09e4e)

Edit:

The only thing that takes a little research is tracking down the C++ libraries
that coincide with the class.

~~~
elteto
Thanks for this. It is worth pointing out to others that these lectures
include videos.

------
minimax
I think I'm in the minority, but I'm happy to see C++ in a college course. I
thought it was all Python and Java these days.

~~~
fsck--off
A friend of mine has a colleague that deliberately uses C++ in an introductory
CS class to "thin the herd" of students he has to teach.

~~~
hvs
CS125 at UIUC was taught in Scheme (using the SICP book no less) as the first
course in CS and it did a pretty thorough job of separating the wheat from the
chaff.

~~~
zerohp
It is now taught in Java while the data structures class (225) is C++. The
Computer Engineering curriculum is going the other way and now teaches
computer architecture, assembly, and C (in that order) before sending students
over to the CS department for data structures.

Former TAs tell me that CompE students find CS 225 to be much easier than
Computer Science students.

~~~
hvs
I can imagine. Just for reference, I graduated in '98, so things have probably
changed quite a bit since I was there. Every class after CS125 used C++
(except AI, which was in Lisp), but C++98 was still in committee and the STL
wasn't really available (templates existed, though). So it really was more
like "C with Classes" than modern C++.

I wonder if CS373 is still destroyer of students that it was in my day. The
average score (before the curve) was around 40%.

------
davvid
Michael Crowley's a great professor and a swell dude. His Operating Systems
class is also a great crash course that forces you into C programming
competence.

------
capkutay
I don't know what the fuss is about with java and python.

It was really beneficial in school to work on large java projects where we
were exposed to eclipse, svn, log4j, junit, jdbc, etc. It was unbelievably
useful going into my job. On the other hand, we used C when we were studying
something low-level like thread communication or operating systems. C/C++
absolutely has its place in the college cs curriculum as do java and python.

------
1O0101ll100O
My school teaches an intro course in python and then switches to c++ for the
data structures and beyond.

It's gotta be easier to just start with c++ and run with it.

~~~
michaelrbock
Just for some context, USC starts intro to CS with C++ and then does Data
Structures in C++, then switches to Java for more advanced OOP. Upper division
classes are usually in Java or C++.

------
krapp
I'm taking C++ (almost through with the beginning semester) after basically
being self-taught in python, js and php. It's interesting, and I can
definitely appreciate how it teaches you fundamentals in a way higher
languages don't necessarily. Sort of like learning to drive stick when all
you've known is an automatic.

------
mhaymo
This seems incomplete without the labs and assignments included. The github
link on the assignments page leads nowhere.

------
zenbowman
I was a teaching assistant for that class for 2 years, HNs got me feeling
nostalgic.

------
shreeshga
I once tried to code an assignment involving TF-IDF on a corpus of docs. It
ran blazingly fast compared to python. But was debugging segmentation faults
until the last minute.

------
jmt7les
Learning C++ was the best. That course is just missing the Algorithm Analysis
which mine had along with Data Structures, all C++ and no #includes allowed.

