• Best of luck to the class of 2024 for their HSC exams. You got this!
    Let us know your thoughts on the HSC exams here
  • YOU can help the next generation of students in the community!
    Share your trial papers and notes on our Notes & Resources page
MedVision ad

The Code Marathon. (1 Viewer)

turntaker

Well-Known Member
Joined
May 29, 2013
Messages
3,908
Gender
Undisclosed
HSC
2015
I'm not quite sure what you mean

To do Key-Value mappings I'd just use a HashMap, why recreate the wheel? Also why the "no method" restriction? Do you mean no static methods or no methods at all? None at all means you can't even print anything... Unless you meant no creation of ADDITIONAL methods, in which case the following (awful) code would fit all the requirements:

Code:
public class Entry
{
    public final K key;
    public final V value; 

    public Entry(K key, V value) {
        this.key = key;
        this.value = value;
    }
}
Then your "app" would have an array of these, it would cycle through them and compare keys to the input key, and once a match is found the value is printed.

This implementation is not OO though. The key idea of OOP is that objects aren't just 'things' that hold data - objects are defined by behaviour and well, this object has none. [emoji14] not to mention it's completely inefficient - like I said, don't reinvent the wheel!

Why am I not studying for my trial tomorrow?
Create a program that does your trials for you.
 

turntaker

Well-Known Member
Joined
May 29, 2013
Messages
3,908
Gender
Undisclosed
HSC
2015
Yep, I agree with KoA. The whole idea of OOP is that classes are defined by the operations(methods) not their fields.
Saying that no methods are allowed goes against the nature of OO.
 

KingOfActing

lukewarm mess
Joined
Oct 31, 2015
Messages
1,016
Location
Sydney
Gender
Male
HSC
2016
You can use built in ones (obviously) but not custom made ones. In practice it'd be better using methods but I found it helped me understand it better doing it this way.

(stupid justification I know lol, but it helped me)

Ill clarify more when I get home
But that's not object oriented - the whole point of the object oriented programming paradigm is to define objects that follow behaviours, such that the internals of the objects can be changed in any way without affecting the methods (behaviours) that define them. All the internal parts of an object should be kept private and inaccessible except for crucial parts.

Anyway, since you say you can use built in methods:

Code:
Map<K,V> map = new HashMap<>();
map.put(foo, bar); //placing entries in map
System.out.println(map.get(foo)); //retrieving entries from map
 

KingOfActing

lukewarm mess
Joined
Oct 31, 2015
Messages
1,016
Location
Sydney
Gender
Male
HSC
2016
hmm..I think I should have used a better word than app in my original post, lol maybe 'exercise'. I digress.

anyway, what OOP is designed for and what programs fall under the category of OOP are two different things. I remember doing this while literally learning about OOP lol. I found it helpful.

Sometimes you might write programs with no real world use, maybe just for the purpose of understanding specific concepts (hence why I said no methods in particular, should have clarified custom methods but thought it'd be obvious). There exists better ways to code a program for the above use I described (obviously).

My original proposal does fall under the category of OOP. We instantiate objects from classes through specific constructors. This already tells us about object instantiation, class creation/behaviour, constructors and depending on the way you decide to approach this task, static variables (I coded mine with and without static variables).

It's definitely not a primer of what OIP should be but it is a good exercise for the reader in how OOP works. Hope this clears things up.

In retrospect I would have probably used a better anology, I just chose whatever came to my mind first lol. Keyboard --> keys.

idk anything about hash tables yet but I don't doubt it's better at doing this then what the goal of my program is (although the purpose would be different). Looks exactly like python dictionaries.
Big misconception actually. OOP isn't about object instantiation, nor classes, nor "static variables". It is programming paradigm that focuses on behavior, and attempts to group similar behaviours together for coherent code. This is contrasting to functional programming, where 'objects' are now functions, and things are thought of as "operators" or "parameters".

Here's an OOP exercise:

Create an Event, EventManager and EventListener classes. The EventManager class should follow the singleton pattern and utilise lazy initialisation. EventListener objects may register themselves as "listeners" to the EventManager through a method register(EventListener), and unregister themselves through unregister(EventListener). The Event class should be a stub. Upon calling EventManager#post(Event), all registered EventListener's should handle the event through a method handle(Event). You should have only one single static variable, and one static method. A smart implementation would utilise an interface instead of a class, somewhere.
 

KingOfActing

lukewarm mess
Joined
Oct 31, 2015
Messages
1,016
Location
Sydney
Gender
Male
HSC
2016
you cant seriously say that object instantion, classes creation and use & static member variables etc are not OOP by nature. The word paradigm and that is an interesting word choice. Paradigm (OED):



This goes back to my previous post. I'm not trying to demonstrate the typical example of the way OOP is best used. Rather, simply show an exercise in which OOP is utilised a particular way. Whether this is effective -- be that as it may -- is another story.

anyway I don't want to distract you from trials, so focus on that, lol.
Object instantiation, class creation and members/variables are all implementation details of programming languages. All Object-Oriented means is that it has a focus on Objects, and those object's attributes and methods. Whilst instances of Objects are always core to OOP (is something the same "Type" of object as another?), the use of constructors is only due to standards, and is not part of the paradigm. I use that term, by the way, because that's what OOP is. It is one style of programming, just like Functional, Procedural or Symbolic Programming. I'm not saying the exercise is a bad example of OOP, I'm saying it's not an example of OOP at all. It's a pretty good exercise for data-management or data-structures, but the focus here is on the data and not the behaviour.

Just to reinforce the point that OOP is just a style - Java itself is in way both functional and procedural. The JVM runs the main(String[] args) method, and once that method returns, the JVM exits.
 

Paradoxica

-insert title here-
Joined
Jun 19, 2014
Messages
2,556
Location
Outside reality
Gender
Male
HSC
2016
Object instantiation, class creation and members/variables are all implementation details of programming languages. All Object-Oriented means is that it has a focus on Objects, and those object's attributes and methods. Whilst instances of Objects are always core to OOP (is something the same "Type" of object as another?), the use of constructors is only due to standards, and is not part of the paradigm. I use that term, by the way, because that's what OOP is. It is one style of programming, just like Functional, Procedural or Symbolic Programming. I'm not saying the exercise is a bad example of OOP, I'm saying it's not an example of OOP at all. It's a pretty good exercise for data-management or data-structures, but the focus here is on the data and not the behaviour.

Just to reinforce the point that OOP is just a style - Java itself is in way both functional and procedural. The JVM runs the main(String[] args) method, and once that method returns, the JVM exits.
+1 for symbolic
 

Flop21

Well-Known Member
Joined
May 12, 2013
Messages
2,807
Gender
Female
HSC
2015
Bump. I want to learn how to code. Which language should I learn? I know R...
It kind of depends what sort of stuff you want to be doing.

If you're at UNSW, why don't you do COMP1917? They teach you C from knowing nothing.

Like if you just wanted to start off doing front end web work (which is fun), try javascript (of course learn HTML & CSS along with it).

If you don't want to learn C, you could try Java.

Maybe people recommend Python, apparently it's a great language. I'm going to learn python next hopefully.
 

He-Mann

Vexed?
Joined
Sep 18, 2016
Messages
278
Location
Antartica
Gender
Male
HSC
N/A
It kind of depends what sort of stuff you want to be doing.

If you're at UNSW, why don't you do COMP1917? They teach you C from knowing nothing.

Like if you just wanted to start off doing front end web work (which is fun), try javascript (of course learn HTML & CSS along with it).

If you don't want to learn C, you could try Java.

Maybe people recommend Python, apparently it's a great language. I'm going to learn python next hopefully.
Thanks for the advice.

My degree requires me to take 6 UOC of computing which I haven't yet done so because of some irrational fear of computing. Many people say computing is easy and is fun but I hear that computing is hard and boring. I'm ok at logic but just not sure.

Why Java?

I heard that too, Python. I'm so indecisive and been delaying this [learning to code] for a year now.
 

KingOfActing

lukewarm mess
Joined
Oct 31, 2015
Messages
1,016
Location
Sydney
Gender
Male
HSC
2016
The language you learn should be dependant on what you need to write.

Applications for phones and games and stuff -> C based language
Indie-esque games, server code, data transmission -> Java
Short scripts -> Python, batch, etc.
Dependency scripts -> Maven stuff, Ant, Gradle, etc.

You can do any thing in any language, technically, but then you get performance and technical issues. As much as beginner courses likes to pretend otherwise, Python is not a good language to write a game, and you shouldn't be writing "hello world" length scripts in Java.
 

He-Mann

Vexed?
Joined
Sep 18, 2016
Messages
278
Location
Antartica
Gender
Male
HSC
N/A
The language you learn should be dependant on what you need to write.

Applications for phones and games and stuff -> C based language
Indie-esque games, server code, data transmission -> Java
Short scripts -> Python, batch, etc.
Dependency scripts -> Maven stuff, Ant, Gradle, etc.

You can do any thing in any language, technically, but then you get performance and technical issues. As much as beginner courses likes to pretend otherwise, Python is not a good language to write a game, and you shouldn't be writing "hello world" length scripts in Java.
I'm considering learning Python now just because it's good for writing short scripts so I can automate some things!
 

Flop21

Well-Known Member
Joined
May 12, 2013
Messages
2,807
Gender
Female
HSC
2015
Thanks for the advice.

My degree requires me to take 6 UOC of computing which I haven't yet done so because of some irrational fear of computing. Many people say computing is easy and is fun but I hear that computing is hard and boring. I'm ok at logic but just not sure.

Why Java?

I heard that too, Python. I'm so indecisive and been delaying this [learning to code] for a year now.
1917 will force you to learn how to code. You go from knowing nothing to being able to solve coding problems. It's pretty cool. Of course that doesn't come without hard work. So you have to go in being enthusiastic, knowing it will be tough at times, but most people before you have gotten through it fine, so you should too.

I say Java, because some unis teach Java first, I have no knowledge of Java so can't speak for it. We do that in second year in COMP2911 at UNSW (apparently the lecturer is crap, so should be fun...). Python is also taught along with some other stuff in COMP2041 at UNSW, it's known for being a beginners language. Go to CodeAcademy and do the course. Doing a course, or part of a course on there will help you get the basic knowledge of things.

Now here's the fun thing about comp courses at UNSW. They're changing most of the first year courses. COMP1917 will be replaced by COMP1511 starting from next sem (Introduction to Programming), so you will get to do the revamped fresh course (it will be very similar, but obviously they've changed things for a reason).

The course drsoccerball linked was COMP1911, which I've heard is like COMP1917 cut in half.

-

So TLDR, my recommendation is just to take COMP1511 (the new course that replaces COMP1917), which will force you to learn C and you can decide if you enjoy it or not and move onto other languages or continue mastering C.

http://webapps.cse.unsw.edu.au/cse/new/courses/COMP1511.php

In the mean time if you're not going to take a comp course for a while but still want to program, learn Python. Start by taking the course on Codecademy. There's also lots of resources online that will help you to choose what language.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top