Valhalla Legends Forums Archive | Excess of Grok | Pointless CS Assignments

AuthorMessageTime
Zakath
Here's a little example of some Java code I had to write for a CS assignment recently:
[code]abstract class FeatVal {
protected Feature ofFeature;

public FeatVal( Feature fFeature ) {
ofFeature = fFeature;
}

public abstract double disSimilarity( FeatVal fFeatVal );
abstract String getValString();

public String toString() {
String sRet = getValString() + " for " + ofFeature.toString();
return sRet;
}
}

class RealVal extends FeatVal {
private double rVal;

public RealVal( double dDouble, Feature fFeature ) {
super( fFeature );
rVal = dDouble;
((RealValFeature)ofFeature).newVal( rVal );
}

public double disSimilarity( FeatVal fRealVal ) {
if ( this.rVal == ((RealVal)fRealVal).rVal )
return 0.0;
else {
double dRet = (this.rVal - ((RealVal)fRealVal).rVal);
dRet = dRet / (((RealValFeature)ofFeature).hiVal - ((RealValFeature)ofFeature).loVal);
if ( dRet < 0 )
dRet = dRet * -1;
return dRet;
}
}

String getValString() {
return String.valueOf( rVal );
}
}

class BoolVal extends FeatVal {
private String bVal;

public BoolVal( String sString, Feature fFeature ) {
super( fFeature );
bVal = sString;
}

public double disSimilarity( FeatVal fFeatVal ) {
if ( this.bVal.compareTo( ((BoolVal)fFeatVal).bVal ) == 0 )
return 0.0;
else
return 1.0;
}

String getValString() {
return bVal;
}
}[/code]

Now...I'm certainly not about to argue that inheritance and polymorphism are bad things (quite the opposite, in fact). But these two classes accomplish basicly the same thing as far as the concepts they're designed to demonstrate...and there were (!)5(!) more classes in a similar vein on this one assignment...all of which had to be done in order to get full credit.

What is it about CS professors that cause them to assign repetitive crap like this? Granted I came into my field with an advantage over many others, but anyone who has progressed to the class I'm currently in successfully is NOT going to need to repeat the same thing 6 times with subtle tweaks in order to learn it. Wouldn't the CS department be better served by covering more concepts, instead of trappling less concepts into the ground? Does this make sense to anybody else?
April 3, 2003, 7:16 AM
Grok
You didn't say what year you were in. I'm assuming this is your first year. Relax, you won't learn anything interesting the first two semesters at most universities. As a sophomore you'll be able to get in better classes, like computer systems architecture, language theory, algorithms.

Don't make the mistake of thinking you really know anything yet. If you're at a university, what you know is pretty meaningless. Universities teach theory and abstraction. If you want pure knowledge of a topic, go to a trade or tech school. They'll teach you lots of immediately useful facts but will leave you unprepared for when your profession changes.

Wait until you are in graduate school to start being critical of the undergrad coursework. Then you'll have a chance to do something about it. In fact, you'll be required to teach undergrad courses, so you can show them how it is supposed to be done. <grin>

Grok?
April 3, 2003, 9:40 AM
Zakath
[quote]This course introduces students to advanced concepts in computational systems and programming languages and builds upon the functional approach to programming.
Topics covered include object-oriented programming, logic programming, stream programming, and parallel systems and programming.
Students will be expected to write programs in object-oriented and logic-based programming languages.
Intended audience: computer science and computer engineering students, and those desiring a deeper understanding of advanced computational paradigms.[/quote]

Normally this course is taken sophomore year, although yes, I'm taking it as a freshman. It's just that the sheer repetitiveness of it is very disconcerting.
April 3, 2003, 2:20 PM
Grok
Just try to remember they're teaching you how to think, not how to do.
April 3, 2003, 3:21 PM
Hostile
Damn community colleges.
April 5, 2003, 8:22 AM
Zakath
Community colleges? I'm attending one of the premier science and technology schools in the northeast - hence why I might expect a little better behavior outta them.
April 5, 2003, 8:45 AM
iago
Grok speaks the truth: you're being taught how to think, not how to get stuff done.

But the university I go to (which isn't premier, but it's still good) has really good assignments, my profs put a lot of thought into them before assigning them. Even though I think 5/term is too many, most classes do that anyway.

Our current assignment in c++ is to write a java-ish Garbage Collector, which is pretty neat. I actually need to ask a question about it, but it's too late right now and I forget what that question is. More to come, tomorrow on the programming forum!
April 5, 2003, 9:12 AM
Zakath
Now that's a neat assignment! Although I can't think of a way to implement it...at least not off the top of my head.
April 5, 2003, 8:40 PM
iago
You can find instructions here, if you want:
http://courses.cs.umanitoba.ca/index.asp?sec=2001&too=30&eve=1&ppa=2163

Basically, take a big array and call it our memory. Whenever somebody makes a call to allocateMemory(int size), we give them a reference number (which, in my implementation, is just a handy way to look it up in a linked list). Then, I create an instance of a class which just holds the index, size, where in the array it begins, and how many pointers are referencing it.

When the number of references reaches 0, it's removed from the linked list.

When we run out of memory or it is requested by the program, the memory is defragmented: every object is moved as close to the beginning of the list as possible, remaining in order. Anything that was removed from the linked list is overwritten, and whatever's left in the list has their location variable updated to the new spot in memory.

The functions I created are:
[code]// These functions don't do anything, but we have to have them so here we go
void initMemory();
void destroyMemory();

// This function will allocate "bytes" bytes of memory and return the index.
// If it is unable to allocate that memory, it will call cleanup() and try
// again. If it is still unable to allocate the memory, it will return
// ERROR and no memory will be allocated.
int allocateMemory(int bytes);

// This function will increment the usage count on the specified index
void addReference(Ref index);

// This function will return a pointer to the actual memory where the object
// is stored. There is no guarentee that it will remain unchanged, though,
// so it is only designed for temporary use.
void *getPointer(Ref index);

// This function will decrement the use count of the object at that index.
// If it is 0, it will be cleaned up next time the garbage collector runs.
// Otherwise, it remains in memory.
void deleteMemory(Ref index);

// This will clean up the unused memory, and defragment the rest.
void cleanUp();[/code]

This would be annoying to use in a real program, so we write a wrapper (template) class for it. The constructor automatically allocated memory, and the = and -> operators are overloaded so we can add and remove references and look up the object.

It's actually a really cool assignment :)
April 5, 2003, 9:16 PM
St0rm.iD
I was bored one day and wrote one. I forget exactly how it worked, but you allocated a "magic pointer" which deleted the object when unreferenced.
April 6, 2003, 1:17 AM

Search