• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

usea

Member
Is it realistic to program a Space Invader clone in C?

We're a group of bloody beginners who have to find a project that we can do as a homework. In my imagination it sounds like a reasonable amount of work. We're gonna use SDL for Video/Audio.

I think the thing I'm most afraid of is the set of enemies, and the ability to kill them off one by one. Are we going to run into problems there?
It definitely depends on how talented you are. For most beginners this would be a 2-3 month homework project, if they could finish at all. However it's probably doable in a few days of hard work if you're awesome. It can vary a lot.

As a teacher, I definitely wouldn't consider it a reasonable amount of work to expect from a beginner student.
 

hitsugi

Member
Don't be fooled be C++ Primer Plus, It's unrelated to C++ Primer which is a much better book. C++ Primer has much more talent behind it, it I know the newest version is extremely nice to use.

Gotcha.. do you think this book could get me up to speed on things? Up to OOP in C++?
 
Can I just say,I love computer science terminology? I've been taking an online course on developing programming languauges, and we just got into some concepts I somehow missed in college, Continuations, Thunking, and Trampolining.

One of my professors in college kept a list of the 5 best CS words, I'd put Thunking and Trampolining up there.

Just curious, my Bachelors in CS never covered these concepts (and I took 2 separate courses in programming languages, one of which covered functional languages extensively), are these just kind of rare concepts, or do I need to go talk to some professors.


FWIW, the online class I'm taking is here http://nathansuniversity.com/ Fun stuff, though the instruction quality is getting worse as the concepts are getting tougher :\
 
It definitely depends on how talented you are. For most beginners this would be a 2-3 month homework project, if they could finish at all. However it's probably doable in a few days of hard work if you're awesome. It can vary a lot.

As a teacher, I definitely wouldn't consider it a reasonable amount of work to expect from a beginner student.

I'd say something like 2 player Tic Tac Toe or Connect 4 would be a good project for a beginner?
 
Can I just say,I love computer science terminology? I've been taking an online course on developing programming languauges, and we just got into some concepts I somehow missed in college, Continuations, Thunking, and Trampolining.

One of my professors in college kept a list of the 5 best CS words, I'd put Thunking and Trampolining up there.

Just curious, my Bachelors in CS never covered these concepts (and I took 2 separate courses in programming languages, one of which covered functional languages extensively), are these just kind of rare concepts, or do I need to go talk to some professors.


FWIW, the online class I'm taking is here http://nathansuniversity.com/ Fun stuff, though the instruction quality is getting worse as the concepts are getting tougher :\

Never heard of those terms. Are they language specific?



Is it realistic to program a Space Invader clone in C?

We're a group of bloody beginners who have to find a project that we can do as a homework. In my imagination it sounds like a reasonable amount of work. We're gonna use SDL for Video/Audio.

I think the thing I'm most afraid of is the set of enemies, and the ability to kill them off one by one. Are we going to run into problems there?

Good luck man, remember my first game it was a disaster if it wasn't for a group member who already programmed for 10 years in c++ and know a lot of game programming stuff.
Do you have to use C or are you guys also allowed to use C# with XNA or Mono C#
 

Darkkn

Member
How advanced knowledge you need to have in order to even bother trying get a job in a programming field?
What are the expectations for someone who is new to the field? It's quite hard to tell what people expect by looking at job postings.

Most 'advanced' program i've done is a standard poker(with gui) program on java with a 'top hands leaderboard' bundled in that uses mysql.
Frankly i think i would be terrified i were to put to work on a real project. I think.

I'm currently doing some courses on Code Academy to get more web oriented programming skills(javascript, node.js etc). Thus far i have found CA to be a pretty good place to do some self-learning.
 

iapetus

Scary Euro Man
How advanced knowledge you need to have in order to even bother trying get a job in a programming field?
What are the expectations for someone who is new to the field? It's quite hard to tell what people expect by looking at job postings.

Most 'advanced' program i've done is a standard poker(with gui) program on java with a 'top hands leaderboard' bundled in that uses mysql.
Frankly i think i would be terrified i were to put to work on a real project. I think.

I'm currently doing some courses on Code Academy to get more web oriented programming skills(javascript, node.js etc). Thus far i have found CA to be a pretty good place to do some self-learning.

To be honest, you sound more experienced and confident from that description than a hell of a lot of people I've interviewed for junior roles.
 

usea

Member
How advanced knowledge you need to have in order to even bother trying get a job in a programming field?
What are the expectations for someone who is new to the field? It's quite hard to tell what people expect by looking at job postings.

Most 'advanced' program i've done is a standard poker(with gui) program on java with a 'top hands leaderboard' bundled in that uses mysql.
Frankly i think i would be terrified i were to put to work on a real project. I think.

I'm currently doing some courses on Code Academy to get more web oriented programming skills(javascript, node.js etc). Thus far i have found CA to be a pretty good place to do some self-learning.
You're not bad off at all. How is your knowledge on cs fundamentals, like data structures etc? A lot of companies focus on these when interviewing. However, if you can demonstrate the ability to actually code things that work (ie: show them something you made and explain part of it like you know what you're talking about), you're most of the way there. Most applicants to programming jobs cannot actually make things.
 

iapetus

Scary Euro Man
Interviewed yes, but accepted? What kind of experience and skill levels did they have?

Both, in some cases. For junior roles I've worked for places that have taken people straight out of university, and some that have required more experience. I've also seen people who really don't have a clue about coding and were out of their depth trying to run a Java program, let alone write one who've received coding jobs. Not anywhere I had anything to do with the interview process, of course; we normally broke that sort of applicant pretty early on. :D

There are still plenty of places that will hire graduates without real experience. To my mind the best thing you can do is learn extra stuff beyond course work on your own initiative, and work on your own projects (or on open source projects - I've improved my chances at a number of job applications in the past through the work I did on JFreeReport).

In my experience you can stand out at any level by showing a real interest in the subject, and by showing you've constantly gone beyond what you've had to do in learning to code (or in doing the minimum to perform your job). As someone going for a junior role, if you can show some understanding of the field and have done enough coding to show that you have intelligent opinions on the tools you're working with, then you'll stand head and shoulders above the majority of the competition.

And frankly, if you're not a little bit terrified of the level of coding you're going to be doing, you probably don't have your sights set high enough. :D
 

injurai

Banned
Gotcha.. do you think this book could get me up to speed on things? Up to OOP in C++?

I'm using 4th ed right now. and OOP is covered. C++ Primer Plus is riding off the popularity and acclaim of the first book, but the C++ Primer is much more acclaimed. Both are good, but if you are dropping your own cash on it go with C++ Primer and the current edition.
 

Harlock

Member
This book is great.

http://www.wired.com/gamelife/2009/03/racing-the-beam/

Racing the Beam: How Atari 2600′s Crazy Hardware Changed Game Design

In the book, Montfort and Bogost explain that the primary difference between the VCS and most every other game console is the machine’s lack of a "frame buffer." This is the section of a system’s RAM that saves the image data for each successive screen that the game displays. The programmer writes each image to RAM, and they are flashed up onto the television screen in succession.

televisionscreen.png
 

Minamu

Member
It seems like my school project is coded in a different version of visual studio 2010 than what I have at home. How do I know what version I should have? :S

I get this error:
http://i.imgur.com/pz1hf.png

Other projects I've done in school before Christmas seem to work just fine o_O
 

usea

Member
contentproj is part of an XNA project. You must not have the xna studio thing installed over VS2010 at home.
 

snorggy

Member
Have a question (coming from someone who hasn't really touched programming since qbasic so sorry if this is moronic):

Are all the different "C" programming languages pretty similar? Are they derivatives of each other like all the different versions of basic back in the day? Meaning, I could learn one "C" language and would be able to adapt my knowledge to other "C" languages as needed?

I ask because my primary interest at this point is iOS app programming which I believe uses Objective-C ... but would possibly like to tackle game programming at some point which I'm lead to believe is largely C++ based...

Any help is appreciated!
 

usea

Member
Have a question (coming from someone who hasn't really touched programming since qbasic so sorry if this is moronic):

Are all the different "C" programming languages pretty similar? Are they derivatives of each other like all the different versions of basic back in the day? Meaning, I could learn one "C" language and would be able to adapt my knowledge to other "C" languages as needed?

I ask because my primary interest at this point is iOS app programming which I believe uses Objective-C ... but would possibly like to tackle game programming at some point which I'm lead to believe is largely C++ based...

Any help is appreciated!
To a certain extent, your ability to program is going to translate from any language to any other language.

As far as similarities go, C and C++ do share some things which make it easier to jump between them than two less-similar languages. Objective-C is not quite as similar, although still more so than some other things. The syntax is pretty different at times, although they're both focused on enabling an object-oriented programming style.

However, this is only one small factor among many that determines how easy it will be to jump into a new language. Your ability to jump into C++ programming after getting good at writing iOS apps will be mostly determined by other factors, not the similarities of the languages. Like, how much general programming knowledge you have, the types of projects you're working on, the style of programming you're doing, etc.

For example, it's totally possible to have a C++ programmer go from working on one C++ project for 2 years onto a new C++ project that looks completely foreign to them. And it's also possible to go from a C++ project to an Objective-C one and have it be mostly familiar. The language is just a part of it, not everything. And especially with C++ there are so many different ways of doing things, one project can look a lot different from the next.
 

snorggy

Member
To a certain extent, your ability to program is going to translate from any language to any other language.

As far as similarities go, C and C++ do share some things which make it easier to jump between them than two less-similar languages. Objective-C is not quite as similar, although still more so than some other things. The syntax is pretty different at times, although they're both focused on enabling an object-oriented programming style.

However, this is only one small factor among many that determines how easy it will be to jump into a new language. Your ability to jump into C++ programming after getting good at writing iOS apps will be mostly determined by other factors, not the similarities of the languages. Like, how much general programming knowledge you have, the types of projects you're working on, the style of programming you're doing, etc.

For example, it's totally possible to have a C++ programmer go from working on one C++ project for 2 years onto a new C++ project that looks completely foreign to them. And it's also possible to go from a C++ project to an Objective-C one and have it be mostly familiar. The language is just a part of it, not everything. And especially with C++ there are so many different ways of doing things, one project can look a lot different from the next.

Thanks for the input and information! Sounds like things are a lot more complex than I anticipated. I've been under the wrong impression that it would more or less be a rather "linear" thing, like the other forms of programming I'm slightly more familiar with (html, basic).
 

usea

Member
Thanks for the input and information! Sounds like things are a lot more complex than I anticipated. I've been under the wrong impression that it would more or less be a rather "linear" thing, like the other forms of programming I'm slightly more familiar with (html, basic).
Definitely. A lot of programming these days is about managing complexity. You have so many requirements for the software to work that the real difficulty lies in meeting all the requirements in such a way that they're easy to change or fix individually.

I'm not sure what kind of basic programming you're familiar with (I've done a little of it, but it was 20 years ago), but programming a game is definitely, absolutely nothing like writing html. HTML isn't even programming, it's markup. There's no logic in it, just "this content is organized like this."

Even a small game can be half a million lines of code, across hundreds of files. I'm not trying to scare you away or anything. Games can be a lot less code too, depending on the tools you use. You can make games without coding at all, or you can make them with just a little code, or a lot. Anybody can make a game, even somebody with no programming experience.

Lua. Ugh.


(I had written more words but screw it.)
My experience with lua is pretty limited, but I remember it fondly. What sucks about it? Rant, you'll feel better :)
 

r1chard

Member
My experience with lua is pretty limited, but I remember it fondly. What sucks about it? Rant, you'll feel better :)
I'm coming from a decade-and-half of professional Python development (and some C, Java, Javascript and even a little PHP, double-ugh.) So I'm not really coming from the nicest place to be criticising Lua :)

I'm learning Moai, which means also learning Lua. So far I've discovered:

1. Lua devs don't document their libraries very well at all. And even the API docs can be thin or neglected (see the current Moai API docs front page which is just plain broken, not to mention the extremely thin details inside.) The majority of stuff I've looked at so far is "documented by example." Ugh. Double-ugh when the damn samples aren't kept up to date with the APIs.
2. It seems that pretty much no-one writes programs in Lua. They all write their own language on top of it (even if it's just extensions in pure Lua) and use that. I've seen a dozen implementations of "class" style things in various libraries. And don't get me started on the integer mess.
3. Of course I really miss the Python standard library. Oh, man do I ever.
4. Shit frequently fails with no explanation. I'm not looking forward to debugging a larger application. I suspect someone out there has written the "Lua but with better debugging" that I need.
5. ":" vs "." seriously?!?

But basically this is all whining. I miss Python but sadly I had zero luck trying to build Kivy apps for Android under either OS X or their pre-built Linux VM. And the pygame subset for Android was too limited for serious development. So I'm trying Moai.
 
Have a question (coming from someone who hasn't really touched programming since qbasic so sorry if this is moronic):

Are all the different "C" programming languages pretty similar? Are they derivatives of each other like all the different versions of basic back in the day? Meaning, I could learn one "C" language and would be able to adapt my knowledge to other "C" languages as needed?

I ask because my primary interest at this point is iOS app programming which I believe uses Objective-C ... but would possibly like to tackle game programming at some point which I'm lead to believe is largely C++ based...

Any help is appreciated!

Objective-C is a strict superset of C, so you can write non cocca code as C and compile it that way.

Objective-C is just a layer on top of C pretty much. Objective-C code can be compiled using GCC or Clang.
 

Anustart

Member
Quick question gaf!

In this xml file:

<?xml version="1.0" encoding="utf-8" ?>
<Jeopardy>
<category name = 'People in Computing'>
<first points = '100' answer = 'Alan Turing'>Known as the questioner of the human mind, this man is known for helping tell humans and computers apart.</first>
<second points = '200' answer = 'Grace Hopper'>This female pioneer of the COBOL computer programming language was an Admiral in the US Navy.</second>
<third points = '300' answer = 'Tim Berners-Lee'>Called the father of the world wide web, this man is the director of the W3C.</third>
<fourth points = '400' answer = 'Lawrence Lessig'>An American academic and political activist who founded the Creative Commons, this man lobbies for reduced legal restrictions on copyrights and trademarks in the technology sector.</fourth>
<fifth points = '500' answer = 'Ada Lovelace'>This woman, known as the world's first computer programmer was also a Countess.</fifth>
</category>

If I am getting data out of this xml file, how do I get the data after the actual answer to the 'question'? i.e. I'm trying to get at the bolded:

<fifth points = '500' answer = 'Ada Lovelace'>This woman, known as the world's first computer programmer was also a Countess.</fifth>

Is there a corresponding node there or what? If I grab the node fifth and then select the attribute answer, the value is Ada Lovelace.

What exactly do I do to get at what I need?
 

usea

Member
You don't want an attribute of the fifth node, you want the value. I'm not sure what the terminology for that is in whatever you're using. Basically, it's everything between:

<fifth>
the question is here
</fifth>

edit:
wait, you're looking for the answer? The answer is Ada Lovelace. Even though it says jeopardy, the xml file isn't using jeopardy terminology for question and answer.
 

Anustart

Member
You don't want an attribute of the fifth node, you want the value. I'm not sure what the terminology for that is in whatever you're using. Basically, it's everything between:

<fifth>
the question is here
</fifth>

edit:
wait, you're looking for the answer? The answer is Ada Lovelace. Even though it says jeopardy, the xml file isn't using jeopardy terminology for question and answer.

Just found out what I was looking for was InnerText :) I just worded what I needed poorly here. I'm a dummy!
 

hateradio

The Most Dangerous Yes Man
What are you using to traverse it? If it's a browser it can also be called textContent -- depending on the browser, sometimes you can also use text or data.
 

squidyj

Member
Is it realistic to program a Space Invader clone in C?

We're a group of bloody beginners who have to find a project that we can do as a homework. In my imagination it sounds like a reasonable amount of work. We're gonna use SDL for Video/Audio.

I think the thing I'm most afraid of is the set of enemies, and the ability to kill them off one by one. Are we going to run into problems there?

I did that in high school but the code was a mess of spaghetti. It was bad under the hood but it worked okay.
 
One more problem with this project I am working on. I am using filterFunction to temporarily remove duplicates (I need the duplicates in some points of sorting so I can't delete them from the ArrayCollection permanently). (Flex4)

Like this:

Code:
model.thisParticularArrayCollection = new ArrayCollection();
model.thisParticularArrayCollection = model.everyItem;
model.thisParticularArrayCollection.filterFunction = removeDuplicates;
model.thisParticularArrayCollection.refresh();

And my removeDuplicates-method looks like this:

Code:
tempObj:Object = {};

			private function removeDuplicates(item:Object):Boolean
			{
				
				

				var retVal:Boolean = false;
			
				if (!tempObj.hasOwnProperty(item.itemnumber)) {
					// if not found add the item to the object
					tempObj[item.itemnumber] = item;
					retVal = true;
					trace(tempObj.toString());
				}
				
				return retVal;
			}

And it works really well, it does what it supposed to do: remove the item from the grid if it's already there. But if I try to sort the list with this tree structure I got, the grid shows up empty. Is there something wrong with my removeDuplicates method

If I trace thisParticularArrayCollection it does seem to have all the objects.

The case is quite similar to this but not with selectedItems http://forums.adobe.com/message/2498791


edit: solved this: arraycollection = arraycollection != arraycollection = copyofarraycollection + need to empty the tempObj after finishing
 

xero273

Member
I am starting to learn javascript and gaffers recommended to use www.codecademy.com. Everything was going well until I reached intro to Objects. I'm confused in how to declare an Object. In the exercises, I declared a different ways and the course would let me pass.

Code:
var myCar = new Object();
    myCar.model = "Corolla";
    myCar.make = "Toyota";
    myCar.color = "red";

Code:
var myCar = 
{
      model : "Corolla",
      make : "Toyota",
      color : "red"
};

Code:
var myCar = {};
    myCar.model = "Corolla";
    myCar.make = "Toyota";
    myCar.color = "red";

The first 2 I seen most commonly used and they work. The last one was used once and worked but the rest of the time i use it, it throws syntax errors.

What is the most common way to declare objects? Thanks
 

usea

Member
I am starting to learn javascript and gaffers recommended to use www.codecademy.com. Everything was going well until I reached intro to Objects. I'm confused in how to declare an Object. In the exercises, I declared a different ways and the course would let me pass.

Code:
var myCar = new Object();
    myCar.model = "Corolla";
    myCar.make = "Toyota";
    myCar.color = "red";

Code:
var myCar = 
{
      model : "Corolla",
      make : "Toyota",
      color : "red"
};

Code:
var myCar = {};
    myCar.model = "Corolla";
    myCar.make = "Toyota";
    myCar.color = "red";

The first 2 I seen most commonly used and they work. The last one was used once and worked but the rest of the time i use it, it throws syntax errors.

What is the most common way to declare objects? Thanks
I usually use the 2nd way. It's also most similar to JSON syntax, which you'll find all over the place.
Here's an example from the jquery api where they use the 2nd method as well http://api.jquery.com/jQuery.post/

For the third method, I don't see any problems with it. I just copied/pasted it into the chrome console and it worked fine.
 

Tristam

Member
Hi GAF, first time for me posting in this thread. My background: I took two years of poorly-taught programming courses in high school. I went on to major in political science in university but seek to return to the coding fold. I currently work on the help desk for the data systems division of a very big school district, and my manager, very cool guy that he is, has placed some basic development-related side projects on my plate.

To ensure that I have good design fundamentals down, for the past six weeks I've been diligently going through Learn Python the Hard Way and am on exercise 41; I breezed through most of the rest of the book, but the script on this page took me quite a few hours to really process in my mind (which was a blow to my confidence!). There remains one part I'm confused by:

Code:
for sentence in snippet, phrase:
    result = sentence[:]

I understand that snippet and phrase are both strings--each snippet being drawn from the PHRASES dict's keys and each phrase being drawn from its items, all of which are passed (as long as the user doesn't quit) to the convert function's two arguments and then separately utilized in the above for loop to append, respectively, converted snippets and phrases to the results list variable, whose value (a two-item list) is returned and assigned to the question and answer variables. (Please correct me if I'm wrong about this being the crux of the script.) What I don't understand is how sentence[:] works here. I know that [:] represents an empty list slice, and that its value in this case equals the snippet or phrase passed to our convert function...but if we create a list (in this case, sentence) and assign it to a new variable (in this case, result), wouldn't result, too, be a list variable? But that can't be so since result is clearly a string--after all, we call the replace function on result and also append result to the results list. In the following example code, though, my_single_list_copy remains a single-item list, not a string...

Code:
my_single_list= ['hey, a single-item list']
my_single_list_copy = my_single_list[:]
print my_single_list_copy

How does this code differ from exercise 41's (in terms of assigning an empty list slice to a new variable)?

Thanks for the help, folks!
 

r1chard

Member
What I don't understand is how sentence[:] works here. I know that [:] represents an empty list slice
No, [:] represents a whole of sequence slice. "You're using the list slice syntax [:] to effectively make a slice from the very first element to the very last one."

As an assignment target [:] will replace an entire sequence's contents with some other sequence.

I hope this helps understand the other stuff :)
 

tuffy

Member
Keep in mind that [:] applied to lists (which are mutable) works differently than when applied to strings (which aren't).
Code:
>>> a = "foo"
>>> b = a[:]
>>> a == b
True
>>> a is b
True
>>> a = [1,2,3]
>>> b = a[:]
>>> a == b
True
>>> a is b
False
In the latter case, the difference becomes apparent when appending a new item to "a" or "b".
 
Can I just say,I love computer science terminology? I've been taking an online course on developing programming languauges, and we just got into some concepts I somehow missed in college, Continuations, Thunking, and Trampolining.

One of my professors in college kept a list of the 5 best CS words, I'd put Thunking and Trampolining up there.

Just curious, my Bachelors in CS never covered these concepts (and I took 2 separate courses in programming languages, one of which covered functional languages extensively), are these just kind of rare concepts, or do I need to go talk to some professors.


FWIW, the online class I'm taking is here http://nathansuniversity.com/ Fun stuff, though the instruction quality is getting worse as the concepts are getting tougher :\

Thunks are a reasonably common concept in functional programming languages in general. It's quite rare to do a course in FP and not cover them I would have thought, since they are just a type of closure. Trampolines come up less often, and the use depends on the context but in terms of FP you see them mentioned on occasion in terms of making it possible to implement proper tail recursion optimisation. The vast majority of programmers who don't work with functional languages will never come across any of these terms but they are more common in the FP world. It's just that the FP world is a teeny tiny subset of all programmers, which is a real shame. (And some things, like how to implement continuations, are of no real interest to a non language designer)
 

xero273

Member
Does the 3rd one give null pointer exception?

I don't know. I have only been using the code on that website to complete the exercises. I used the third method like once and the exercise let me pass. when i get to creating objects within objects, the third method just gives me syntax errors. I'll just stick with the 2nd method since it seems like that is what is most commonly used.
 
Hello,

I'm looking for some advice about web development. I'm trying to figure how I can insert images into a multi line text box via windows drag & drop. I have a c++ background so web development is pretty new to me.

Are there any existing technologies that do this? If no then any recommendation on what direction I would have to go to develop this?

Thank you.
 

Bollocks

Member
Hello,

I'm looking for some advice about web development. I'm trying to figure how I can insert images into a multi line text box via windows drag & drop. I have a c++ background so web development is pretty new to me.

Are there any existing technologies that do this? If no then any recommendation on what direction I would have to go to develop this?

Thank you.

Well I don't know any specific framework, there are already proven stable text editors but I don't know about their drag&drop functionality, look for HTML5 Drag&Drop.
 

LuffyZoro

Member
Good lord, reading the crazy stuff you guys do...I'm just now teaching myself Java. Having fun with Karel the Robot using Stanford lectures that were put online for help. Having a blast.
I did those and had some fun with them. The hardest thing I did was program a version of PacMan in it, which was difficult since it doesn't natively support inputs.
 

hateradio

The Most Dangerous Yes Man
I am starting to learn javascript and gaffers recommended to use www.codecademy.com. Everything was going well until I reached intro to Objects. I'm confused in how to declare an Object. In the exercises, I declared a different ways and the course would let me pass.

. . .

The first 2 I seen most commonly used and they work. The last one was used once and worked but the rest of the time i use it, it throws syntax errors.

What is the most common way to declare objects? Thanks
Using new anything is unsavory in JS, when declaring basic types. The last one and the second one are actually called literals.

Code:
var literalObject = {};
var literalArray = [];
var literalBoolean = true;
var literalString = 'string';
var literalInteger = 1;

There are constructors to each of those, but, again, using the literal is more common (at least by people who have been using JS for a while). I think there are also some speed and small memory concerns when using new, because it has to create a new instance.

Here's a benchmark example. http://jsperf.com/object-new-vs-literal
 

r1chard

Member
Keep in mind that [:] applied to lists (which are mutable) works differently than when applied to strings (which aren't).
The only difference regarding slicing (and this applies to all mutable/immutable sequences) is that you can't assign to an immutable sequence's slice.

Code:
>>> a = "foo"
>>> b = a[:]
>>> a == b
True
>>> a is b
True
>>> a = [1,2,3]
>>> b = a[:]
>>> a == b
True
>>> a is b
False
This is demonstrating the string interning implementation detail of the "C"Python interpreter that is not guaranteed to be present in any other implementation. You get the same effect with:
Code:
>>> a = "spam"
>>> b = "spam"
>>> a is b
True
This can work for quite long strings. I'm not sure what the actual interning algorithm is.

Note that integers (which are also immutable) up to 255 (IIRC) are also not only interned, but pre-allocated by the CPython interpreter.

When you start poking around you might even find other fun edge case optimisations:
Code:
>>> a = "this is a really long string"
>>> b = "this is a really long string"
>>> a is b
False
>>> "this is a really long string" is "this is a really long string"
True
The important message here is: don't use is unless you really, really mean it :)
 
Woo-hoo, tomorrow might be the last day I am working on this awful "please fix me awfully because I am awful program" and might be able to move to similar program (or maybe it's even more awful!).

And I start to get paid to do it so that's a plus
 
I am starting to learn javascript and gaffers recommended to use www.codecademy.com. Everything was going well until I reached intro to Objects. I'm confused in how to declare an Object. In the exercises, I declared a different ways and the course would let me pass.

Code:
var myCar = new Object();
    myCar.model = "Corolla";
    myCar.make = "Toyota";
    myCar.color = "red";

Code:
var myCar = 
{
      model : "Corolla",
      make : "Toyota",
      color : "red"
};

Code:
var myCar = {};
    myCar.model = "Corolla";
    myCar.make = "Toyota";
    myCar.color = "red";

The first 2 I seen most commonly used and they work. The last one was used once and worked but the rest of the time i use it, it throws syntax errors.

What is the most common way to declare objects? Thanks


I usually use 2 if I know everything up front, 3 if I have to do add as I go along (like if I'm building up to something).

It's usually a combination of the two, where you have some variables in the object already and then you add a few more after the fact.
 
Hey guys, new to this thread. :)

I was wondering if anyone knew any good online resources to use to learn Javascript, a couple of friends and I are working on some projects and they're vastly better at this programming thing than I am, I'm the donut bitch for the group right now. Any help would be appreciated. :)
 
Top Bottom