The Student Room Group

Newbie Coders Chat

Scroll to see replies

Reply 180
Original post by Tootles
20 years C and C++ experience, have designed and implemented (via simulation) my own instruction set over a weekend, and wrote a VT100 control library - over another weekend.

Also a real programmer can parse code in any language, even ones they don't know, and can pick up new languages in less than a day.


I think its appropiate to introduce BrainF here.
Whats it print toots ?

++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++>+++++++++++++>++++++++++++++>+++++++++++++++>++++++++++++++++<<<<<<<<<<<<<<<<-]>>>>>>>>>.<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<>>>>>>>>>>>>>>-.+<<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>>>>-.+<<<<<<<<<<<<<<<>>>>>>>>>>>>>>-.+<<<<<<<<<<<<<<>>>>>>>>>>>>>>++.--<<<<<<<<<<<<<<>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<>>>>>>--.++<<<<<<.
Original post by Tootles
20 years C and C++ experience, have designed and implemented (via simulation) my own instruction set over a weekend, and wrote a VT100 control library - over another weekend.

Also a real programmer can parse code in any language, even ones they don't know, and can pick up new languages in less than a day.


Not if it's extremely low level, ie. Assembly, or if it's like BrainF.

As for your second statement, it really depends what language it is, and how different it is from their current language(s).
#include <iostream>
using namespace std; //you might not like it written this way?
int main ()
{
cout << "HELLO WORLD! What language do you think this is?";
return 0; //I know that it's not necessary to do return 0 anymore
}
(edited 7 years ago)
Reply 183

public abstract class Robot<T> where T:s-smilie:peechEngine
{
protected void Initialise(T engine){
engine.Initialise();
Console.Out.WriteLine("Initialising robot");
}
}


public interface SpeechEngine {
void Initialise();
}

public class AlexaVoice:s-smilie:peechEngine
{

public void Initialise()
{
Console.Out.WriteLine("Initialising Alexa speech engine");
}
}

public class SiriVoice : SpeechEngine
{

public void Initialise()
{
Console.Out.WriteLine("Initialising Siri speech engine");
}
}

public class MrRobot : Robot<SpeechEngine>
{
SpeechEngine voice;

public MrRobot(SpeechEngine voiceArg){
voice = voiceArg;

}

public void Greet()
{
Initialise(voice);
Console.Out.WriteLine("Hello world");
}
}


class Program
{

static void Main(string[] args)
{

MrRobot alexa = new MrRobot(new AlexaVoice());
alexa.Greet();

MrRobot siri = new MrRobot(new SiriVoice());
siri.Greet();
Console.ReadKey();
}
}


Wonder if anyone can understand whats going on with this c# robot. Need to be sharp on your c# and OOP for this one.
Maybe one for 57 as its using advanced language features.
(edited 7 years ago)
Reply 184
Original post by 571122
I suppose I'll introduce myself for the fun of it, even though I'm a professional-level graduated programmer.

I'm also (re-)teaching myself programming because it's been a few months ago I last programmed (at my internship corporation). Unless you are a gifted programming and logic genius (like my internship partner was), you need to constantly keep up your skills, or you will lose those skills almost entirely (like me). The IT industry is a lifelong learning one.

Right now I'm busy studying something else that has more priority, but on my todo list is the following:

- medium-advanced Java, C#, .NET technologies (there are a lot of those, including WCF, Web API,..)
- communication languages such as XML, JSON
- web frameworks such as KnockoutJS, Ember, AngularJS (even though that's a crappy language, there is a lot of demand for it on the IT market)

My goal is to finally get rid of my medium-novice status and grow affinity for programming, even though inherently I don't understand logic (I'm an artist by heart). My biggest goal is to get a job with my skills. I just graduated from a Bachelors in Computer Science, but man have my skills weakened. I need to get back on the boat and start actively re-studying and re-practicing all of this.

Stage I'm at: I'm probably a medium-advanced programmer, depending on how you look at it, like my professor said: "Computer scientist with great potential". I know most of the advanced things you can do with programming as well as software engineering: enterprise design patterns etc.

Furthermore, I know too many technologies to sum up. I'll just list a few:

- Java, C#, PL/SQL, SQL, C/AL, VB .NET, WebAPI, Entity framework, JSON, XML, HTML5, CSS3, JS, servlets, JSP, struts, AngularJS, Android, Spring, Hibernate, distributed systems

If anyone has any programming problems concerning Java or C#, feel free to ask me for assistance.

Happy learning!


One thing i'd say looking at that list is don't spread yourself too thin.
WCF or WebAPI.
Entity VS Hibernate.
Knockout,Angular,Ember

All big technologies competing with eachother

Don't try learn them all theres not enough time in the world and its a waste of time just pick one(obviously do your research so its an educated decision) Then learn the others as needed.
(edited 7 years ago)
Original post by _gcx
Not if it's extremely low level, ie. Assembly, or if it's like BrainF.

As for your second statement, it really depends what language it is, and how different it is from their current language(s).
Most languages' syntax are ultimately derived from Algol through C or some such-which, so it isn't really a challenge.

Except if it's PL/M. I think Kildall was on drugs.
Original post by INTit
One thing i'd say looking at that list is don't spread yourself too thin.
WCF or WebAPI.
Entity VS Hibernate.
Knockout,Angular,Ember

All big technologies competing with eachother

Don't try learn them all theres not enough time in the world and its a waste of time just pick one(obviously do your research so its an educated decision) Then learn the others as needed.

I needed to be good at both of them to graduate because both Oracle and Microsoft are in my undergraduate program. That is of course logical, because universities want to bring value to the IT market and so, students have to be versatile in their baggage.

If only it were that simple to make a choice. At my internship, there were projects with Angular, then we would be thrown on other projects with Knockout, and the story goes on.
It's of course a fact that in the IT world you have to specialize, for there are many sub-specializations on offer.

I don't really like programming, but I'm glad I have a good foundation.
(edited 7 years ago)
// Using a C# feature called 'generics' because you see the use of the type 'T' between the less than and greater than signs. The 'where' expression: this forces that a certain generic paramater T has to conform to something, in this case you can only pass in SpeechEngine types (where T is a type). This promotes less errors because you can't pass in the wrong type or call a wrong method.We want to make this class abstract so that you can't instantiate a Robot. We want the Robot class to contain the commonalities shared by its children classes.

public abstract class Robot<T> where T:s-smilie:peechEngine
{
protected void Initialise(T engine){ // A generic and flexible Initialise() method. It's protected so that only child classes can call it.
engine.Initialise(); // We call the Initialise() method of whatever SpeechEngine variety (type) was passed in. We see below that this prints out a SpeechEngine-specific text.
Console.Out.WriteLine("Initialising robot":wink:; // Whenever we call the Initialise(engine) method, "Initialising robot" will be printed to the console output.
}
}

// Whatever uses the SpeechEngine interface, must have an Initialise() method. Again, this way you are promoting less errors (for example, forgetting to call that method, or giving it a different, non-standard name).
public interface SpeechEngine {
void Initialise();
}

public class AlexaVoice:s-smilie:peechEngine // An Alexa Voice is a Speech Engine
{

public void Initialise() // Mandatory implementation, therefore conformity and standardization. We are using the method that we got from the interface we inherited.
{
Console.Out.WriteLine("Initialising Alexa speech engine":wink:;
}
}

public class SiriVoice : SpeechEngine // The same goes for the Siri Voice
{

public void Initialise()
{
Console.Out.WriteLine("Initialising Siri speech engine":wink:;
}
}

// MrRobot is a Robot that has a SpeechEngine. Seeing MrRobot extends the Robot class (inherits it, and therefore inherits its members) As you can see, MrRobot is the class we want to actually instantiate because it has no 'abstract' keyword restricting it from instantiation
public class MrRobot : Robot<SpeechEngine>
{
// interface for polymorphism: which voice do we want? Conceptually, we are saying that a MrRobot robot has a speech engine that belongs to it (composition, like an engine belongs to a car).
SpeechEngine voice;

public MrRobot(SpeechEngine voiceArg){
// When we create our MrRobot, we also give it a speech engine
voice = voiceArg; // Our robot will have the passed-in SpeechEngine variety so that it will greet us in that voice.
voice = voiceArg;

}

public void Greet()
{
// We call our SpeechEngine's Initialise(voice) method that we got through inheritance from our Robot class, who has access to the SpeechEngine's Initialise(T engine) method
Initialise(voice);
Console.Out.WriteLine("Hello world":wink:;
}
}


class Program // Our main program that will execute our logic that we put together
{

static void Main(string[] args) // The main entry point that will cause the compiler to locate it and execute our program
{

MrRobot alexa = new MrRobot(new AlexaVoice()); // We create a MrRobot that gets passed in a new AlexaVoice anonymous instance.
alexa.Greet(); // We ask alexa, a MrRobot, to greet us with its AlexaVoice SpeechEngine

MrRobot siri = new MrRobot(new SiriVoice()); // We do the same for the SiriVoice
siri.Greet();
Console.ReadKey(); // We read the next key that the user types into the console. This is a way to artificially pause a running program because the program waits until the user presses a key.
}
}
I wrote my comments to the code in my quote above.

Technically, what's going on here is ultimate flexibility by use of interfaces and generics and an added bonus of coding error prevention. Why generics? Because we want to let other developers specify for themselves what type our classes are going to be, but more importantly, because we don't want runtime errors due to incorrect casting/type boxing. For example, without generics, we would be forced to specify the type T at compile time: if we make a Robot of type string, the developers that would use our Robot class would have to cast each of our strings to integers, in the case they would want to use integers, but I'm getting too much into detail here.

Basically, we created a general Robot class for a MrRobot class to inherit and we want it to not just be any robot, but we want it to have a Speech Engine, so that it can talk. We create two robots, Alexa and Siri, and we have them greet us, each with their own specialized greeting.

I hope that's enough explanation for now.
Happy coding.
Original post by 571122
So, from what I can read, your program is like this:

1) You have a HelloWorld class with a main block that accepts commandline arguments. It prints "Hello, World" to System.out.

2) You got into learning about classes and Object-Oriented programming and you made a Robot entity, that has a name, a constructor that takes a name and sets it as the Robot's name.

Then you have a private method named 'speak' (denoting an action) that defines the Robot's behavior. Executing this method makes the Robot say whatever message was passed in as well as whatever name was passed into the constructor.

The Robot is then responsible for its own execution, so a main method has been added. A new Robot instance named "r" called "debbie" is created, the speak method is executed upon that instance and the line "hey there! it's me..." is passed into it.A new Robot is created with instance name "b" and his name is "bob". His speak method is executed and the line "My name is..." is passed in.Consequently, the debbie robot will say "hey there! it's me...debbie" and the bob robot will say "My name is...bob".

Furthermore, we see the use of Java's specialized I/O Scanner class from the Java util package. A Wheel class is defined with a radius attribute.A constructor is defined with one argument 'radius', which will define the Wheel's radius.A function called getCircumference returns a double with the outcome of the local calculation.A similar function getArea() is created.

Then, the Wheel defines the main method, in which the program starts by asking the user to provide valid input. A Scanner will then be responsible for reading that input (as it reads what comes into System.in). A double is defined, representing whatever valid double was passed in by the user and this is then printed out to the user.

Lastly, a Wheel instance named 'w' is created using this provided double. The Wheel's dimensions then get printed out using the calculations on that double.


Correct 571. I today finished work on my latest project, which is more or less my own code, as opposed to those other three which were ready made progs. And It runs in drjava like a dream, with no runtime errors. However when i attempt to upload it to vocareum, it fails on all counts apart from style i think. So there is something wrong with either a, the code b, the layout c, the filename or d, my use of the input software. I am praying that the problem is d, and a simple system refresh, or other easy tweak will sort it out. But I have already submitted it twice, and got zero marks the first time, and only a couple on the second. Have a look at the program and see if you can spot any obvious factors which would cause it to fail the online mark scheme in this way, thanks!

import java.util.Scanner;public class AboutMe { public static void main (String[] args) {Scanner s = new Scanner(System.in);System.out.print("What is your name?":wink:; String myName=s.nextLine();System.out.print("What school do you attend?":wink:;String mySchool=s.nextLine(); System.out.print("How old are you?":wink:; int myAge=s.nextInt(); System.out.println("My name is "+myName+", I attend "+mySchool+" and I am "+myAge+" years old.":wink:;String input = s.next();s.close(); }}

http://pastebin.com/iVZGVs3h
(edited 7 years ago)
Original post by 571122
// Using a C# feature called 'generics' because you see the use of the type 'T' between the less than and greater than signs. The 'where' expression: this forces that a certain generic paramater T has to conform to something, in this case you can only pass in SpeechEngine types (where T is a type). This promotes less errors because you can't pass in the wrong type or call a wrong method.We want to make this class abstract so that you can't instantiate a Robot. We want the Robot class to contain the commonalities shared by its children classes.

public abstract class Robot<T> where T:s-smilie:peechEngine
{
protected void Initialise(T engine){ // A generic and flexible Initialise() method. It's protected so that only child classes can call it.
engine.Initialise(); // We call the Initialise() method of whatever SpeechEngine variety (type) was passed in. We see below that this prints out a SpeechEngine-specific text.
Console.Out.WriteLine("Initialising robot":wink:; // Whenever we call the Initialise(engine) method, "Initialising robot" will be printed to the console output.
}
}

// Whatever uses the SpeechEngine interface, must have an Initialise() method. Again, this way you are promoting less errors (for example, forgetting to call that method, or giving it a different, non-standard name).
public interface SpeechEngine {
void Initialise();
}

public class AlexaVoice:s-smilie:peechEngine // An Alexa Voice is a Speech Engine
{

public void Initialise() // Mandatory implementation, therefore conformity and standardization. We are using the method that we got from the interface we inherited.
{
Console.Out.WriteLine("Initialising Alexa speech engine":wink:;
}
}

public class SiriVoice : SpeechEngine // The same goes for the Siri Voice
{

public void Initialise()
{
Console.Out.WriteLine("Initialising Siri speech engine":wink:;
}
}

// MrRobot is a Robot that has a SpeechEngine. Seeing MrRobot extends the Robot class (inherits it, and therefore inherits its members) As you can see, MrRobot is the class we want to actually instantiate because it has no 'abstract' keyword restricting it from instantiation
public class MrRobot : Robot<SpeechEngine>
{
// interface for polymorphism: which voice do we want? Conceptually, we are saying that a MrRobot robot has a speech engine that belongs to it (composition, like an engine belongs to a car).
SpeechEngine voice;

public MrRobot(SpeechEngine voiceArg){
// When we create our MrRobot, we also give it a speech engine
voice = voiceArg; // Our robot will have the passed-in SpeechEngine variety so that it will greet us in that voice.
voice = voiceArg;

}

public void Greet()
{
// We call our SpeechEngine's Initialise(voice) method that we got through inheritance from our Robot class, who has access to the SpeechEngine's Initialise(T engine) method
Initialise(voice);
Console.Out.WriteLine("Hello world":wink:;
}
}


class Program // Our main program that will execute our logic that we put together
{

static void Main(string[] args) // The main entry point that will cause the compiler to locate it and execute our program
{

MrRobot alexa = new MrRobot(new AlexaVoice()); // We create a MrRobot that gets passed in a new AlexaVoice anonymous instance.
alexa.Greet(); // We ask alexa, a MrRobot, to greet us with its AlexaVoice SpeechEngine

MrRobot siri = new MrRobot(new SiriVoice()); // We do the same for the SiriVoice
siri.Greet();
Console.ReadKey(); // We read the next key that the user types into the console. This is a way to artificially pause a running program because the program waits until the user presses a key.
}
}
I wrote my comments to the code in my quote above.

Technically, what's going on here is ultimate flexibility by use of interfaces and generics and an added bonus of coding error prevention. Why generics? Because we want to let other developers specify for themselves what type our classes are going to be, but more importantly, because we don't want runtime errors due to incorrect casting/type boxing. For example, without generics, we would be forced to specify the type T at compile time: if we make a Robot of type string, the developers that would use our Robot class would have to cast each of our strings to integers, in the case they would want to use integers, but I'm getting too much into detail here.

Basically, we created a general Robot class for a MrRobot class to inherit and we want it to not just be any robot, but we want it to have a Speech Engine, so that it can talk. We create two robots, Alexa and Siri, and we have them greet us, each with their own specialized greeting.

I hope that's enough explanation for now.
Happy coding.


Can you tell me how to use pastebin correctly? I have located the site, and copied the code, but it just shows the url link, and not the actual code itself. What am i doing wrong??
Original post by john2054
Can you tell me how to use pastebin correctly? I have located the site, and copied the code, but it just shows the url link, and not the actual code itself. What am i doing wrong??

I find it strange because you already posted a correct pastebin sample.
I'm not sure what problem you are having. Could you tell me more? Maybe you already figured it out.

As far as I know, you use pastebin like this:
1) Go to http://pastebin.com/
2) Click inside 'New paste', paste your code inside there
3) Choose a particular syntax highlighting for your language
4) Choose how long you want your post to be valid on the site (Expiration)
5) Choose a title for your paste
6) Click create new paste (you might be required to fill in some captcha first)
Original post by Craghyrax
How well does javascript prepare you for other kinds of programming?

Javascript (scripting; i.e. writing interpreted code to run inside a single execution engine such as a browser or a NodeJS instance) prepares you for other kinds of programming (i.e. writing compiled code) in the sense that it lets you first play with basic programming concepts first such as loops, conditions, variables in memory, control structures,.. and so on, before you move on to more difficult concepts such as Objected-Oriented Programming. Once you have those simple constructs down, you can move to a programming language; it's a way to ease yourself into programming, but it's only a choice. For example, I started with Java; I read a book from A to Z, I read my syllabus and I used the javadocs. I also had a look at the conceptual overview.
Simon Allardice gives a short explanation on it, here.

n.b.: Javascript works internally very different from Java, so if you get crazy (arithmetic) results, don't be too surprised. The language itself was written in a couple of days.

As for the question 'how well' it prepares you: it prepares you for basic programming concepts. For more advanced concepts, you'll need to use a programming language.
(edited 7 years ago)


It's been a while for me since I used the Scanner class, but I compiled and ran your code and I received no errors. Line 17 might be redundant, as you tell the Java compiler to wait for input before it closes the program, but you aren't further expecting any input, but maybe you just wanted the program to pause. I just typed in some random character followed by enter and the program closed as expected.

Did you compile and run the code already?

n.b.: the file name of your program has to be AboutMe.java
(edited 7 years ago)
Hey, I'm trying to teach myself Python and HTML/CSS but it's a slow process.
Original post by LogicalFallacy
Hey, I'm trying to teach myself Python and HTML/CSS but it's a slow process.


Is there anything in particular that you're struggling with?
Original post by _gcx
Is there anything in particular that you're struggling with?


I'm going to be honest and say:

1.

Time

2.

Finding a space to experiment with HTML and CSS

Original post by 571122
It's been a while for me since I used the Scanner class, but I compiled and ran your code and I received no errors. Line 17 might be redundant, as you tell the Java compiler to wait for input before it closes the program, but you aren't further expecting any input, but maybe you just wanted the program to pause. I just typed in some random character followed by enter and the program closed as expected.

Did you compile and run the code already?

n.b.: the file name of your program has to be AboutMe.java


Yes thanks 57, i compiled and ran my code, and i am fairly sure that i named the file correctly. Although some times i have doubts over even that.

I have also taken a look at the second program we are asked to do, and my results are pretty bad, although to be honest with you i'm running out of patience. Although i suppose you need patience in spades to get the hang of this.

I also don't know whether this second program is actually meant to compile (which would make sense), or if it is supposed to just demonstrate an executive functional block, without working itself. They don't make this clear. Here is my code for this one, see what you think...

http://pastebin.com/j7b810AH

BTW this one doesn't even compile, god help me!?

Finally i have also looked at the next project i have to do, and thank hell it is a more mathematical based project, with some basic bolean operations, but i am hopeful that i can do better here. Although with things as there currently stand, i will be lucky to scrape a pass if i can't bring my grades up, on this other stuff!
Original post by john2054

I have also taken a look at the second program we are asked to do, and my results are pretty bad, although to be honest with you i'm running out of patience. Although i suppose you need patience in spades to get the hang of this.

That's right, patience is critical in programming.


I also don't know whether this second program is actually meant to compile (which would make sense), or if it is supposed to just demonstrate an executive functional block, without working itself. They don't make this clear. Here is my code for this one, see what you think...

http://pastebin.com/j7b810AH

BTW this one doesn't even compile, god help me!?

I corrected it and now it compiles. Check it out here:
http://pastebin.com/376JZa4c

Here are the answers to your questions:
- Yes, the second program is meant to compile and so it did after I amended it.
- It is supposed to demonstrate Objected Oriented Programming, and more specifically the use of functions (methods that return a value; a method is a function that belongs to a class), their return values and using those.

I ran the code now and the results are that it prints the following:

I really like your shoes!
What are THOSE?


A few tips for further improvement:
- When you write code, always make sure you open and close your braces before you do anything else, otherwise you might forget to close some braces and then your code will not be valid.
- Don't add too much whitespace between code. Make it clean.
- Always indent correctly (normally it's 4 spaces per tab for good style). Whatever you write inside a code block needs to be indented, i.e.: code inside a class needs to be indented 4 spaces after the 'public class' line. Code inside a method needs to be indented 4 spaces after the 'public someMethod()' declaration
Original post by 571122
That's right, patience is critical in programming.


I corrected it and now it compiles. Check it out here:
http://pastebin.com/376JZa4c

Here are the answers to your questions:
- Yes, the second program is meant to compile and so it did after I amended it.
- It is supposed to demonstrate Objected Oriented Programming, and more specifically the use of functions (methods that return a value; a method is a function that belongs to a class), their return values and using those.

I ran the code now and the results are that it prints the following:


A few tips for further improvement:
- When you write code, always make sure you open and close your braces before you do anything else, otherwise you might forget to close some braces and then your code will not be valid.
- Don't add too much whitespace between code. Make it clean.
- Always indent correctly (normally it's 4 spaces per tab for good style). Whatever you write inside a code block needs to be indented, i.e.: code inside a class needs to be indented 4 spaces after the 'public class' line. Code inside a method needs to be indented 4 spaces after the 'public someMethod()' declaration


Thanks 57, do you want paying for this? If i pass the mooc, i can drop you a dollar or two, if that would help?
Original post by 571122
That's right, patience is critical in programming.


I corrected it and now it compiles. Check it out here:
http://pastebin.com/376JZa4c

Here are the answers to your questions:
- Yes, the second program is meant to compile and so it did after I amended it.
- It is supposed to demonstrate Objected Oriented Programming, and more specifically the use of functions (methods that return a value; a method is a function that belongs to a class), their return values and using those.

I ran the code now and the results are that it prints the following:


A few tips for further improvement:
- When you write code, always make sure you open and close your braces before you do anything else, otherwise you might forget to close some braces and then your code will not be valid.
- Don't add too much whitespace between code. Make it clean.
- Always indent correctly (normally it's 4 spaces per tab for good style). Whatever you write inside a code block needs to be indented, i.e.: code inside a class needs to be indented 4 spaces after the 'public class' line. Code inside a method needs to be indented 4 spaces after the 'public someMethod()' declaration

This isn't Python, indentation is irrelevant.

Quick Reply

Latest

Trending

Trending