Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Exams

Name: Anonymous 2006-12-19 0:33

Hey /prog/

Had a programming examination today. I'm a second year comp. eng student at McMaster in Canada, and man, the kind of grief the exam gave my friends and I was..haha it was rough.

But as I was looking at the questions on the exam (for reference, it was basically Java, & C++), I had to ask myself: "What the hell is so great about OO programming?"

When it comes to Java, it bothers me that all objects are passed by ref, that casts are only checked at run-time, and just, well the overall slugishness I seem to feel when I'm trying to develop code. Is it wrong to feel a lack of interest (and a lack of a good mark) in a course I'm supposed to be enjoying, and paying for out of my own pocket?

I'm not going to pretend I'm a whiz kid at programming, I know there are members of /prog/ who could laugh at the questions had they seen the exam.

Anyways, I wanted to hear from you guys, share your experiences of crappy setbacks in college/uni from comp sci/software eng/comp eng, etc.

Name: Anonymous 2006-12-19 4:34

>>1
I understand your questions.

What the hell is so great about OO programming?
Not much. It's a good way not to fuck up, but there are others. It's a good idea to create independent structures, units or objects that maintain their own data. Note, though, that the only difference between MyClass.Lol(myobj) and myobj.Lol() is syntax.

The reason why they're all hyped on OO is that OO was the previous business shit that kept every manager busy wanking to OO. Businessmen (who can be distinguished by three features: rule this industry, have no fucking idea of it, and always have to fuck everything up) are obsessed with OO because they read in a magazine that it's so great because "it increases your company's productivity by enabling software architects to benefit from code reutilization and information hiding, creating a smooth flow of work that will maximize your business profits and help creating enterprise-ready scalable business solutions implementing your business logic". That's business-speak, get used to hating it because you will, all your life.

When it comes to Java, it bothers me that all objects are passed by ref
Java is useless, but all objects passed by ref is a good thing. It's easier to understand in languages such as Python. Passing by reference means more efficiency (copying is slower and creates objects in memory which probably have to be garbage collected afterwards), it means you don't have to define a copy operation for each object (remember copying objects is not always as easy as copying each property: the object may have open files, etc., stuff you can't or don't want to happily copy), and it allows for certain magic that you'll discover in due time.

casts are only checked at run-time
Java's type system is made of anal and shit. Don't expect it to do anything right. But get used to dynamic typing. In a decent language, this is possible:

i = 1
i = "Now I'm a string, lol"

# Let's create a class right now and here
class MyClass(object):
    def Method(self):
        return "I lol'd"

# A completely different class now; doesn't inherit from MyClass or anything
class MyClass2(object):
    def Method(self):
        return "Yoshinoya"

# Let's create a function here
def CallMethod(x):
    print x.Method()

i = MyClass()
CallMethod(i) # "I lol'd"
i = MyClass2()
CallMethod(i) # "Yoshinoya"
# Note that CallMethod doesn't expect x to be of any particular type. All it requires is that it has a method "Method" to call.

# More fun: A function which returns a class? In Mother Russia it's possible.
def CreateClass(inherits, method1):
    class NewClass (inherits): # Inherited class is passed by the caller
        MyMethod = method1 # They pass us this method, we use it here
    #Return the newly-created class to the caller
    return NewClass

# Create a class like MyClass and MyClass2 with this method:
def TempMethod(self):
    return "What? Method? Function? It's actually the same."
MyClass3 = CreateClass(object, TempMethod)
i = MyClass3()
print i.MyMethod() # "What? Method? Function? It's actually the same."



the overall slugishness I seem to feel when I'm trying to develop code
That's because Java sucks. It's about as unproductive as C, only slower and more annoying to work with. Not only the language is flawed in more ways than I have time to explain, but the standard library is pure hell. When you have to instantiate three classes with long names to print a fucking line of text on a file, something is wrong.

Is it wrong to feel a lack of interest (and a lack of a good mark) in a course I'm supposed to be enjoying
It's not wrong. Stay away from Java or you'll end up hating this trade. For low-level/speed-critical/VROOM VROOOM stuff use C; for everything else, I recommend Python, Ruby, LISP, Haskell, etc.; real languages. You'll find them so much more interesting and fun to learn and use. Python (what I used in my example) and Ruby (similar set of features) are more traditional approaches (though take "traditional" with a grain of salt), while LISP is more powerful but less uh... conventional, and Haskell is a pure functional programming language.


>>2
Meta-troll


>>5
I struggle with lists being a collection of object references.
That's what makes them efficient. Careful with mutable objects though.

If I want a method to return that list, I get stuck with a copy of the same references
Very simple stuff in a decent language. If your elements have a copy() method, and you have a language which supports functional programming features, you could try returning something like map(MyClass.copy, mylist). But you rarely need to copy every element of a list, really. You can post a short description of what you wanted to do and why you needed copies, and I'll help you.


>>6 is a wise person.


>>7
What really bugs me about writing code on paper is that paper doesn't lend itself well to the way I do things. For example, I like putting in my brackets first, and then filling them with content, but you can't really do that on paper.
I feel your pain! This is exactly what I do and why I hated programming exams.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List