The Student Room Group

Newbie Coders Chat

Scroll to see replies

I'll just grab my Web Development notes here:

Yes, nested functions are closures.

With nested functions you have access to variables at definition time (in their scope by lexical context), in contrast to C#, which uses execution context.
The great advantage of using closures is that you still have access to variables after the containing function has ended, through the use of a hidden [[scope]] pointer on the heap.

In JavaScript, if you declare a function within another function, then the local variables can remain accessible after returning the function you called.
http://stackoverflow.com/questions/111102/how-do-javascript-closures-work

There is no class keyword in Javascript, but you can do the following:
function AnObject(){
}

var my = new AnObject();
my.name = "John";
my.definition = function { ... }

The problem with the above approach is that the object properties 'name' and 'definition' (arbitrarily chosen) have only been defined for instance 'my'.

var yours = new AnObject();
alert(yours.name) // returns UNDEFINED

Solutions to this problem:
- Constructor function
- Prototype

Constructor function: you have to use the this keyword to define public variables and functions (and to define private ones, you use the var keyword)

Prototype:

To add properties and methods to all instances of an object, outside of the constructor. We use the prototype property for this and every object has it.

Javascript is not a real OO language because it's missing the following features:
- namespaces, encapsulation, interfaces, inheritance

What can we do about that? We can imitate these by making specific coding agreements:
use of scope, context and closures.

Namespaces:
You use the object literal notation as a singleton so that you can emulate namespaces.

Encapsulation:
Use naming conventions such as prefixing all private members with an underscore.
Also via closures:
- constructor defines private attributes through the var keyword
- constructor defines privileged methods through the this keyword
- public methods without access to private attributes through prototype keyword

Interfaces through duck typing.

In summary:
- Use the first code example to emulate namespaces so that you have unobtrusive code
- Use the third example to have more flexible code

If your platform is resource-poor, try to consider efficient memory and CPU pipeline use of the various approaches (also referred to as 'micro-optimization':wink:.
Reply 261
Original post by 571122
I'll just grab my Web Development notes here:

Yes, nested functions are closures.

With nested functions you have access to variables at definition time (in their scope by lexical context), in contrast to C#, which uses execution context.
The great advantage of using closures is that you still have access to variables after the containing function has ended, through the use of a hidden [[scope]] pointer on the heap.

In JavaScript, if you declare a function within another function, then the local variables can remain accessible after returning the function you called.
http://stackoverflow.com/questions/111102/how-do-javascript-closures-work

There is no class keyword in Javascript, but you can do the following:
function AnObject(){
}

var my = new AnObject();
my.name = "John";
my.definition = function { ... }

The problem with the above approach is that the object properties 'name' and 'definition' (arbitrarily chosen) have only been defined for instance 'my'.

var yours = new AnObject();
alert(yours.name) // returns UNDEFINED

Solutions to this problem:
- Constructor function
- Prototype

Constructor function: you have to use the this keyword to define public variables and functions (and to define private ones, you use the var keyword)

Prototype:

To add properties and methods to all instances of an object, outside of the constructor. We use the prototype property for this and every object has it.

Javascript is not a real OO language because it's missing the following features:
- namespaces, encapsulation, interfaces, inheritance

What can we do about that? We can imitate these by making specific coding agreements:
use of scope, context and closures.

Namespaces:
You use the object literal notation as a singleton so that you can emulate namespaces.

Encapsulation:
Use naming conventions such as prefixing all private members with an underscore.
Also via closures:
- constructor defines private attributes through the var keyword
- constructor defines privileged methods through the this keyword
- public methods without access to private attributes through prototype keyword

Interfaces through duck typing.

In summary:
- Use the first code example to emulate namespaces so that you have unobtrusive code
- Use the third example to have more flexible code

If your platform is resource-poor, try to consider efficient memory and CPU pipeline use of the various approaches (also referred to as 'micro-optimization':wink:.


Good notes although JS does support inheritance through prototype and 'constructor stealing':
https://jsfiddle.net/3atskdkc/1/
You got to admire Javascripts simplicity :wink:
(edited 7 years ago)
Original post by INTit
Good notes although JS does support inheritance through prototype and 'constructor stealing':
https://jsfiddle.net/3atskdkc/1/
You got to admire Javascripts simplicity :wink:

JavaScript is anything but simple. It's every developer's nightmare. If you know how the JavaScript engine parses, executes and allocates its variables (as opposed to how you think it does that) then you are good with Javascript, because it does it in an incredibly unintuitive way that has developers scream with frustration.

Let's not forget the zillion bugs JS has.. it's a complete nightmare. Every developer agrees.
Commonly used image in JavaScript lectures and developer talks:
(edited 7 years ago)
Reply 263
Original post by 571122
JavaScript is anything but simple. It's every developer's nightmare. If you know how the JavaScript engine parses, executes and allocates its variables (as opposed to how you think it does that) then you are good with Javascript, because it does it in an incredibly unintuitive way that has developers scream with frustration.

Let's not forget the zillion bugs JS has.. it's a complete nightmare. Every developer agrees.
Commonly used image in JavaScript lectures and developer talks:


Haha yea the more the more you know the more the worse it gets.
Original post by 571122
Try not to let others mess you up. Rough times are a part of life though. Best of strength. Stay focused.


Original post by Craghyrax
Sorry to hear about your situation. You seem very young to be married? Not a judgement, but I think that makes it harder because you are both still growing and maturing.
If you can, arrange to see a marriage counsellor.
Next thing to do is to spend time reflecting on exactly what the issues are. Identify your own needs, and also your own failures. You need to be honest about things that you can't do, or cope with. Then you need to find a way to communicate these in a calm way, and using language that is as neutral as possible. Frame things in terms of your needs and feelings and never in terms of her faults. This will make it more likely that she is able to hear you without reacting and that a productive conversation can take place.
If she could do the same, that would be great. Sometimes this stuff is just too hard to verbalise in person. An email or letter might really help you.

It's also worth keeping an open mind about whether you think your marriage can work, or should work after you've spent the time to analyse precisely what your different needs are and precisely what your personal limitations are. If you think that you can improve and mature so as to be able to give the other what they need, and avoid causing them pain... then great. But there's a possibility that you won't be able to... or that doing so would seriously undermine your own happiness. If that is the case then there is no shame in deciding to let the marriage go. There is a lot of cultural stigma surrounding divorce. But there is a gamut of psychological research confirming that divorce is far better for happiness than an unhappy marriage in the long term. So don't rule that out.
All the best :smile:

Thanks for the support 571 and Crag. I think i am over the worst of it now. I had been drinking a lot of coffee, and then being very clingy to her. I will need to address that. The thing is we don't always live in this world, but the next one. I don't certainly. What i mean by that is that, i need to get my priorities straight. But i still have this interview tomorrow morning i think i may have told you about. And assuming things don't go the way of the titanic, i am trying to remain positive. Plus this morning she told me that it was me who was pushing for a divorce. Stay tuned....
Original post by INTit
Haha yea the more the more you know the more the worse it gets.

I love this JS talk about JS's funny little bugs, check it out:

[video="youtube;et8xNAc2ic8"]https://www.youtube.com/watch?v=et8xNAc2ic8[/video]

It's not all that mysterious though, just ugly.
Hi. :smile:

I've decided to learn to code with the objective of making my own smartphone game - I have a few really good ideas which I just need to know the means of bringing them to life!

Has anyone used Kilobolt?

I'm on Unit 1 where it'll teach me about Java. At the end of Unit 4, i'll be able to port my probably awful first game to android and possibly play it on my phone!

Anyone had any experience with it? I'm very excited. :smile: Seems hard!
does anyone know how to program a voice recognition app so that when you speak to it it does what you ask it say for example 'turn off the light' or just ask it a question and it gives you the answer??
Reply 268
Original post by kaylababesxx
does anyone know how to program a voice recognition app so that when you speak to it it does what you ask it say for example 'turn off the light' or just ask it a question and it gives you the answer??
*

You could probably hook something up using a speech recognition api which would then communicate with a Raspberrry pi/ micro-controller like the Arduino to control the lights.

One DIY route would be to try find a voice recognition api for the raspberry pi then wire a circuit to control the lights which you could control programatically via the PIs GPIO pins.
Unless you really know what your doing with electricity stick to LEDs and not mains power lights !

* If that doesn't sound fun or you want it to control mains lighting then just buy an Amazon Echo and some smart bulbs :tongue:
(edited 7 years ago)
Original post by Craghyrax
Sorry to hear about your situation. You seem very young to be married? Not a judgement, but I think that makes it harder because you are both still growing and maturing.
If you can, arrange to see a marriage counsellor.
Next thing to do is to spend time reflecting on exactly what the issues are. Identify your own needs, and also your own failures. You need to be honest about things that you can't do, or cope with. Then you need to find a way to communicate these in a calm way, and using language that is as neutral as possible. Frame things in terms of your needs and feelings and never in terms of her faults. This will make it more likely that she is able to hear you without reacting and that a productive conversation can take place.
If she could do the same, that would be great. Sometimes this stuff is just too hard to verbalise in person. An email or letter might really help you.

It's also worth keeping an open mind about whether you think your marriage can work, or should work after you've spent the time to analyse precisely what your different needs are and precisely what your personal limitations are. If you think that you can improve and mature so as to be able to give the other what they need, and avoid causing them pain... then great. But there's a possibility that you won't be able to... or that doing so would seriously undermine your own happiness. If that is the case then there is no shame in deciding to let the marriage go. There is a lot of cultural stigma surrounding divorce. But there is a gamut of psychological research confirming that divorce is far better for happiness than an unhappy marriage in the long term. So don't rule that out.
All the best :smile:

I am 35 you know?

Anyway we are over the worst of it.

And back to my programming course, i have passed the first three weeks with a grade over 50%, which is what i was aiming for. Hopefully if i keep this up i may just scrape a c pass overall. But I'm not going to kill myself over it,

See attached <>

computerscv2.jpg
Here are my scores for C# and stuff. I paused doing the course for a while because I have to study something else, but I'll get back on it sometime soon!

Original post by 571122
Here are my scores for C# and stuff. I paused doing the course for a while because I have to study something else, but I'll get back on it sometime soon!


Yes but the difference between you and me is that you know how to code, and i haven't done it in over twenty years. I also have pass grades for personal finance, psychiatric drug maintence and social media as well. What is the bredth of your study 571?
Original post by john2054
Yes but the difference between you and me is that you know how to code, and i haven't done it in over twenty years. I also have pass grades for personal finance, psychiatric drug maintence and social media as well. What is the bredth of your study 571?

Yeah, sorry for bragging there. :tongue:

Well, my education entails a lot of courses, which is a very broad knowledge baggage. I don't really know how to program well, you see, I don't have a talent, like good coders do. I just know the basics. A few grades from uni I suppose I'll show:

Accounting: 90%
Financial analysis: 80%
Communication 101: 90%
Computer architecture: 60%
Web development: 70%
Object Oriented Programming 101: 75%
Logic theory and data structures 101: 50%
Systems theory: 60%
Operating systems theory: 65%
Network architecture 101: 60%
Networking 101: 60%
Networking 201: 60%
Databases 101: 60%
Databases 201: 50%
Software Engineering 101: 60%
Project Programming 101: 60%
Software Engineering 2: 60%
Systems theory 201: 60%
OO programming 201 (Java, .NET): 60%, 70%
Databases 301: 65%
Software Engineering 301: 60%
Multimedia technologies: 70%
Communication 201: 70%
XML and data technologies: 90%
Communication 301: 70%
Statistics 101: 50%
Project management: 50%
Performance management: 90%
ICT law: 85%
Programming 301: 65%
Enterprise Resource Planning : development: 85%
Finals programming project: 60%
UI design 301: 65%
Programming 401: 60%
Distinction research paper: 80%


And that concludes my degree.
I still haven't mentioned the other ones from my community college degree, but I'm too tired for that. It's more or less the same.
I also did a third degree on Social Media Management.. argh... I forgot to mention that.. anyway.
Original post by 571122
Yeah, sorry for bragging there. :tongue:

Well, my education entails a lot of courses, which is a very broad knowledge baggage. I don't really know how to program well, you see, I don't have a talent, like good coders do. I just know the basics. A few grades from uni I suppose I'll show:

Accounting: 90%
Financial analysis: 80%
Communication 101: 90%
Computer architecture: 60%
Web development: 70%
Object Oriented Programming 101: 75%
Logic theory and data structures 101: 50%
Systems theory: 60%
Operating systems theory: 65%
Network architecture 101: 60%
Networking 101: 60%
Networking 201: 60%
Databases 101: 60%
Databases 201: 50%
Software Engineering 101: 60%
Project Programming 101: 60%
Software Engineering 2: 60%
Systems theory 201: 60%
OO programming 201 (Java, .NET): 60%, 70%
Databases 301: 65%
Software Engineering 301: 60%
Multimedia technologies: 70%
Communication 201: 70%
XML and data technologies: 90%
Communication 301: 70%
Statistics 101: 50%
Project management: 50%
Performance management: 90%
ICT law: 85%
Programming 301: 65%
Enterprise Resource Planning : development: 85%
Finals programming project: 60%
UI design 301: 65%
Programming 401: 60%
Distinction research paper: 80%


And that concludes my degree.
I still haven't mentioned the other ones from my community college degree, but I'm too tired for that. It's more or less the same.


Why are all of the grades rounded off. Be honest, you didn't take any of them? And you photoshopped that mooc grade as well. Am i right?!
Original post by john2054
Why are all of the grades rounded off. Be honest, you didn't take any of them? And you photoshopped that mooc grade as well. Am i right?!

I don't know what suddenly got into you, John. All the grades I posted are real and I actually opened up my online 'education history board' so I could write my grades out for you. They are all rounded up because that's how my uni grades students. I wouldn't post my results so proudly if I haven't slaved years for them.
Original post by 571122
I don't know what suddenly got into you, John. All the grades I posted are real and I actually opened up my online 'education history board' so I could write my grades out for you. They are all rounded up because that's how my uni grades students. I wouldn't post my results so proudly if I haven't slaved years for them.


Okay but i still don't believe this :
'I also did a third degree on Social Media Management.. argh... I forgot to mention that.. anyway.'

Also you do realise that your degree is basically an enhanced computer science degree. The fact that it has diverse things such as project management in it is good.

But for my degree i covered english, drama, theatre, education, sociology, spss (data input), and health studies. So you see if it is a points contest on diversity, i think i win there. Plus i have a wife and stepdaughter. Which is really the ultimate trump card i'm afraid to say.

Good luck with your coding.

PS please don't take any of this personally, because i still need you to help me with that java mooc, which i am only half way through, thanks again!!??
Original post by john2054
I am 35 you know?

Anyway we are over the worst of it.

And back to my programming course, i have passed the first three weeks with a grade over 50%, which is what i was aiming for. Hopefully if i keep this up i may just scrape a c pass overall. But I'm not going to kill myself over it,

See attached <>

computerscv2.jpg


Where are my manners? :smile: Congratulations John, well done. Keep it up.
Original post by john2054
Okay but i still don't believe this :
'I also did a third degree on Social Media Management.. argh... I forgot to mention that.. anyway.'

Also you do realise that your degree is basically an enhanced computer science degree. The fact that it has diverse things such as project management in it is good.

But for my degree i covered english, drama, theatre, education, sociology, spss (data input), and health studies. So you see if it is a points contest on diversity, i think i win there. Plus i have a wife and stepdaughter. Which is really the ultimate trump card i'm afraid to say.

Good luck with your coding.

PS please don't take any of this personally, because i still need you to help me with that java mooc, which i am only half way through, thanks again!!??

Well, when I was finishing up my Computer Science degree, I actually took interest in writing and social media.. which I took a degree in and excelled at because it favors my artistic side more (I'm an artist). I completed those two at the same time. :smile: You can't just have a one-directional way in life, you know? You have to expand your interests and live.

Well, it's not an enhanced computer science degree, that would be a Masters; it's just that, a Bachelors. Bachelor degrees don't consist of just the basic computer science courses, you know, they also require general knowledge (hence all the extra courses), which is exactly what distinguishes it from a community college degree, which is completely specified and one-directional.

I've had a lot of experience in life, as you may know, and I also did drama in high school, music, drawing, printing press, marketing, art, pointillism, still life, ,.. Ah yes, we used SPSS in our stats101 class. :smile: In high school, I also did a second specialization next to the general one, which was 'sports school', which included First Aid and olympic sports.

Would you like to tell me why you have this drive for competition? I tell you my life and my results out of passion but you seem to be fetching for approval.. it's not very friendly, you know? If you want my help, then I suggest you apologize for your gloating.. Come on man, what's that about? "I have a wife and kids and I trump you"? What the heck..
Original post by 571122
Well, when I was finishing up my Computer Science degree, I actually took interest in writing and social media.. which I took a degree in and excelled at because it favors my artistic side more (I'm an artist). I completed those two at the same time. :smile: You can't just have a one-directional way in life, you know? You have to expand your interests and live.

Well, it's not an enhanced computer science degree, that would be a Masters; it's just that, a Bachelors. Bachelor degrees don't consist of just the basic computer science courses, you know, they also require general knowledge (hence all the extra courses), which is exactly what distinguishes it from a community college degree, which is completely specified and one-directional.

I've had a lot of experience in life, as you may know, and I also did drama in high school, music, drawing, printing press, marketing, art, pointillism, still life, ,.. Ah yes, we used SPSS in our stats101 class. :smile: In high school, I also did a second specialization next to the general one, which was 'sports school', which included First Aid and olympic sports.

Would you like to tell me why you have this drive for competition? I tell you my life and my results out of passion but you seem to be fetching for approval.. it's not very friendly, you know? If you want my help, then I suggest you apologize for your gloating.. Come on man, what's that about? "I have a wife and kids and I trump you"? What the heck..

I can even trump Ronald himself, with the fact that i had, and to quote my psychiatrist, acute chronic schizophrenia, you know the kind criminals have, and i got better from that as well.

The fact that you have graduated means that you are my peer. True you know a lot more about coding than me, but we all have different strengths and weaknesses. To be honest my marriage is a bit like the stock markets, one minute it is going well, and the next it is peaking on collapse. What state are you from btw? Thanks to f.b. i have had a few close american friends, over the past few years or so.

Quick Reply

Latest

Trending

Trending