• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tyranus

Thinking in Javascript

7 posts in this topic

Hello, i've been reading the forums for a few months but never started a topic or participated in any discussions till now.

 

I've been using Python for 2-3 years mainly focusing on Web Development with Django/Flask and decided it was time to learn javascript, but not just getting some random snippet to work on my website which is as painful as it gets right now. I want to know what's really going on.

 

Watching a talk by Douglas Crockford he said something like "To fully understand the beauty of JS you need to think in JS, many people code Python/C/Java in JS and that doesn't cut it" (i think it was along those lines, if i find that video again i'll post the quote)

 

I'm reading the book Eloquent Javascript (http://eloquentjavascript.net/contents.html) but i don't think that'll be enough.

 

Does anyone have any links or book recommendations?

 

Thanks!

2

Share this post


Link to post
Share on other sites

I tend to learn programming easier by thinking up something I want to achieve then attempting to code it (and asking questions about 'How to do...' along the way) rather than reading books and doing exercises. Thats how I learnt/am learning Javascript. But this may not be how you learn.

 

But if you do, I'd try to do something like 'Move a div from the left of the screen to the right' or 'Get some XML from a server'.

 

Javascript is really powerful because there isn't quite anything called a class, yet you can still achieve sub-classing, polymorphism and abstraction.

 

An example is:

var someVariable= {"key": "value"}; // this a map

someVariable["Anonymous Function"] = new function(someParams) {
    consolelog(someParams);
};

// call anonymous function
someVariable["Anonymous Function"]("blah");

someVariable = [1, 2, 3]; // this is now an array

// I think you can do this also but may need to check
someVariable = {someProperty: 1.1};
console.log(someVariable.someProperty);  // almost treat the variable as a class with properties.


Edited by gretty
2

Share this post


Link to post
Share on other sites

I think you'll be fine with the book you're reading and maybe a handy reference. JS is pretty straightforward once you understand the idea behind HTML, CSS, and DOM in general.

 

"To fully understand the beauty of LEGOs you need to think in LEGOs, many people build with art/science/efficiency in LEGOs and that doesn't cut it"

1

Share this post


Link to post
Share on other sites

I'm a longtime-lurker, and haven't posted before, but sometime has to be the first!
When I learned javascript I also started with a Python-background. I think my biggest problem was that I was trying to code javascript in the same fashion that I coded Python. 

I would recommend to just start coding as much as possible, then switch to some common framework(angular,backbone) and get a feel for how common javascript is written. Looking at the sourcecode for a couple of larger open-source projects might also be very helpful to get a feel for js-syntax. 

I recently wrote a blogpost about learning javascript which might or might not be helpful, 
http://pointnull.com/learn-javascript/

Oh and if you're a Python programer, you might want to look into Coffeescript, http://coffeescript.org/, the syntax is awesome and quite similar to Python. 


 

Edited by fischebyxa
1

Share this post


Link to post
Share on other sites
The main problem of many programmers is, in my opinion, the desire to do everything just like they did it in other languages. Best example: object orientation.
In JavaScript, there are no classes. The only JavaScript thing which is close to be what a class in other languages is, are the constructors. (And constructors are regular functions which are used for object instanciation elsewhere.)

While working with JavaScript, keep in Mind: there are no private members. Every member is public. (Same goes for Python: "private" members will only be translated, e. g. from "__privateMember" to "_MyClass_privateMember". Knowing this, you can still access private members, but it's evil...)
In general: instead of relying on specific types you should just use objects as if they are what you expect them to be. For at least some type safety or "method overloading" you could do some type checking, but for objects of types other than the primitive types you should just check if they provide the features (methods and/or members) you need.
This also means: you have to use inheritance much less compared to other languages.

You should definitely take a look at what closures are and what you can do using them in JavaScript. Those are used frequntly to hide implementation specific functions to keep the global context clean. (-> Anonymous function containing all library setup calls, which is called immidately.)
Also Closures are used to have some kind of private "members", but due to what a closure is, those are no members ob the object. You will run into some troubles if you want to combine it with inheritance. ;)


@gretty:
var someVariable = {"key":"value"}
This is not a map, it's an object. (You can assign values to an array usign a non numeric key as well, but it still would be an array.)
1

Share this post


Link to post
Share on other sites

I agree with Buster2000 (it's a hacker language) and I've even written  book about JavaScript that I won't mention here because that could turn this post into spam.

One good thing about JavaScript is that it becomes what you intend it to be.  Depending upon which libraries you choose to use.

That's why if you want to create business apps which display forms to users and save data in a database you should use AngularJS.

However, if you want to build games, then you want to know everything about HTML Canvas -- which is manipulated via JavaScript.

Since this is gamedev.net, I will assume that is what you want.  

If that is what you want, then you definitely want the following book (not written by me, so this isn't spam):

HTML 5 Canvas (amazon link) by Steve Fulton & Jeff Fulton

This book is very readable and like having a mentor which guides you through the great sample code which builds with each chapter.

Keep in mind -- in case you're wondering why the book title doesn't mention JavaScript -- that HTML5 = HTML, JavaScript & CSS

Also keep in mind when you manipulate the HTML Canvas element you use JavaScript.  

The book even works you through creating a couple of games.

Keep on learning, keep on programming.

~Newton

1

Share this post


Link to post
Share on other sites

Thanks a lot for the responses, i've finished reading the book and to my surprise i wasn't that far off from the 'correct' way to use javascript.

 

 

I tend to learn programming easier by thinking up something I want to achieve then attempting to code it (and asking questions about 'How to do...' along the way) rather than reading books and doing exercises. Thats how I learnt/am learning Javascript. But this may not be how you learn.



But if you do, I'd try to do something like 'Move a div from the left of the screen to the right' or 'Get some XML from a server'.

 

 

Indeed, i've used Javascript this way for a while now most of the time using jQuery.

 

 

The problem with Javascript is that it is a hackers language. If you look up several Javascript projects on Github and compare them some of hem will look like they have been written in completly different languages.

 

 

 

 

gretty is probably right. Just do a few projects in Javascript. The key to Javascript is that its a "getting things done" language and not a "making code look pretty" language.

 

 

Yeah, i think the most awfully written code i've seen was in JS (it worked like a charm but still, couldn't follow most of what was coded)

 

 

I think you'll be fine with the book you're reading and maybe a handy reference. JS is pretty straightforward once you understand the idea behind HTML, CSS, and DOM in general.



"To fully understand the beauty of LEGOs you need to think in LEGOs, many people build with art/science/efficiency in LEGOs and that doesn't cut it"

 

 

Thanks for the link Khatharr, and for the LEGO quote laugh.png

 

 

I would recommend to just start coding as much as possible, then switch to some common framework(angular,backbone) and get a feel for how common javascript is written. Looking at the sourcecode for a couple of larger open-source projects might also be very helpful to get a feel for js-syntax.

I recently wrote a blogpost about learning javascript which might or might not be helpful,
http://pointnull.com/learn-javascript/

 

 

I've started looking into AngularJS and Nodejs a few days ago, that should keep me busy for a while, thanks for the blog link by the way!

 

 

The main problem of many programmers is, in my opinion, the desire to do everything just like they did it in other languages. Best example: object orientation.
In JavaScript, there are no classes. The only JavaScript thing which is close to be what a class in other languages is, are the constructors. (And constructors are regular functions which are used for object instanciation elsewhere.)

While working with JavaScript, keep in Mind: there are no private members. Every member is public. (Same goes for Python: "private" members will only be translated, e. g. from "__privateMember" to "_MyClass_privateMember". Knowing this, you can still access private members, but it's evil...)
In general: instead of relying on specific types you should just use objects as if they are what you expect them to be. For at least some type safety or "method overloading" you could do some type checking, but for objects of types other than the primitive types you should just check if they provide the features (methods and/or members) you need.
This also means: you have to use inheritance much less compared to other languages.

You should definitely take a look at what closures are and what you can do using them in JavaScript. Those are used frequntly to hide implementation specific functions to keep the global context clean. (-> Anonymous function containing all library setup calls, which is called immidately.)
Also Closures are used to have some kind of private "members", but due to what a closure is, those are no members ob the object. You will run into some troubles if you want to combine it with inheritance. ;)

 

 

Excellent, great advice. I've read and fiddled with closures in Python before but never applied them in any of my projects. With what you tell me it seems they have a niche in JS, will definitely look into it some more.

 

 

However, if you want to build games, then you want to know everything about HTML Canvas -- which is manipulated via JavaScript.

Since this is gamedev.net, I will assume that is what you want.

If that is what you want, then you definitely want the following book (not written by me, so this isn't spam):

HTML 5 Canvas (amazon link) by Steve Fulton & Jeff Fulton

 

 

That would be one of my goals, correct. Thanks for the heads up and the book recommendation, if you don't mind send me your books name via PM so i can check it out.

 

I'll check out some game dev resources on HTML5/JS and Python and probably will post on the Game Programming forum next time.

 

Thanks again!

 

 

 

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0