Would learning a bit of Javascript corrupt my mind?

I’m interested in the opinion of the folk here who can do proper programming…

I’ve been wanting to learn a programming language for a while, to understand more about that side of things and also for practical purposes of scripting, text processing, etc. And, wanting to do things properly, I plumped for Python, as it seems fairly powerful but is also recommended by many, many people as a first language to learn. I bought a book and everything, though I haven’t actually started yet.

But it turns out that what would really help me in the short term is to learn some Javascript, as I could use that directly in InDesign to do all sorts of useful stuff. My question is: if I get into Javascript first, will that make learning Python more difficult? People say that Python gets you into good habits, and I’ve heard that Javascript can get you into bad ones. Is there any way I could avoid that?

You want to learn Javascript and still avoid learning bad programming habits. Hard to do I’m afraid. The problem is that it is likely that you’ll have to do things in Javascript which would be considered harebrained if implemented the same way in Python. Python comes with a vast set of libraries. Not so with Javascript. When I wrote code in Javascript, there have been a few times when something which would have taken one line or two lines in Python ended up taking several lines in Javascript. The Javascript code was needlessly long and convoluted from a Python perspective.

[quote=“lemur”]You want to learn Javascript and still avoid learning bad programming habits. Hard to do I’m afraid. The problem is that it is likely that you’ll have to do things in Javascript which would be considered harebrained if implemented the same way in Python. Python comes with a vast set of libraries. Not so with Javascript. When I wrote code in Javascript, there have been a few times when something which would have taken one line or two lines in Python ended up taking several lines in Javascript. The Javascript code was needlessly long and convoluted from a Python perspective.[/quote]Thanks, Lemur.

Still wondering about automating InDesign, though. Apparently you can do it in Python too, but not directly in InDesign itself. It sounds complicated. You have to do it through something called COM, and I think you have to figure out how to do it yourself. I haven’t turned up any comprehensive resources on it.

Doing it in Javascript just sounds a lot easier. And there are quite a few ready-made scripts out there to adapt. Isn’t there the programming equivalent of thick rubber gloves I could wear to prevent infection? :wink:

I wish!

Javascript is a really nice language. It’s clean and simple, and it has everything a base language needs: a variety of useful built-in types, sane scoping rules, an elegant functions-as-classes OOP approach, real closures, and good memory management.

There is certainly a lot of bad Javascript on the web, but I think that has more to do with the browsers (and the strain of manipulating XML) than with Javascript itself.

I think it’s a great starter language, as is Python.

[quote=“Brendon”]Javascript is a really nice language. It’s clean and simple, and it has everything a base language needs: a variety of useful built-in types, sane scoping rules, an elegant functions-as-classes OOP approach, real closures, and good memory management.

There is certainly a lot of bad Javascript on the web, but I think that has more to do with the browsers (and the strain of manipulating XML) than with Javascript itself.

I think it’s a great starter language, as is Python.[/quote]Thanks, Brendon. I was hoping you would write something here, as I know you’re a big Python fan.

So you really don’t think that using Javascript means it’s more difficult to write efficient code in other languages later?

If I do learn some Javascript first, how difficult would it be to switch to Python afterwards, do you reckon? And how deep into Javascript should I get before doing that? Is it better to learn one language fairly thoroughly before starting another?

No, I don’t think so. It’s important to get a good grip on the fundamentals of programming – control flow, data structures, common algorithms and patterns[1]. To do that, you want a language that keeps out of your way as much as possible and lets you focus on those things. Javascript is pretty good for that, mostly.

They have more similarities than differences – they’re both procedural, object-oriented and dynamically typed, they have many of the same facilities available. Don’t be scared of going back and forth between languages, at least within the same general area. Once you understand how one works, writing in another is mostly just about learning a little syntax and finding a library reference.

I wouldn’t say so. If anything, I encourage you to play with as many as you can. Seeing the places they do different things helps understand what each is about.

Then again, Python is still a great first choice. It’s also easier to experiment with than Javascript in many ways – it’s easier to use as a stand-alone language (instead of in a plugin or a browser) than Javascript, and there’s a lot of introductory material that focuses on becoming a good programmer (rather than just getting some specific task done).

This is a really great introduction to programming (via Python), and it’s free!

Also, IRC is a great place to get help. In particular Freenode is a huge programmer community, with a #python and a #javascript where you can ask questions about anything. I learned more about Python by hanging around there than I did any other way.

[1]: Not “Design Patterns”, ugh. Just approaches to problems.

[quote=“Brendon”]
This is a really great introduction to programming (via Python), and it’s free![/quote]

Peekaboo.

I just started browsing that link and it’s really easy reading.

I work in marketing so probably won’t ever need to do any programming but interesting to see how it all works.

Cheers for that B-dog. :slight_smile:

[quote][i]One approach is to think of the computer as an employee with certain strengths, like speed and precision, and particular weaknesses, like lack of empathy and inability to grasp the big picture.

Your job is to be a good manager: find ways to take advantage of the strengths and mitigate the weaknesses.[/i] [/quote]

F*@k you computer, you’re fired!

No but learning a little C++ will corrupt your stack and heap.

Not to mention giving you a bad case of hex dumps…

Not to mention giving you a bad case of hex dumps…[/quote]
Ooooh. I had the core dumps before. Bad news.

Actually if I were going to learn a web language now it would be ActionScript for Flash, because Flash is cross browser and you can do some cool stuff in it.

E.g.
novelconcepts.co.uk/FlashElementTD2/

I’ve seen attempts at this sort of thing in Javascript but it ends up really ugly and only working on the browser the guy developed it uses. Of course Flash support tends to be bad or non existent on mobile devices, which is a downside.

Mind you if you’re trying to build Ajax websites you need to use Javascript, and possibly Javascript will end up working as well as Flash does today for dumb games. It’ll take a long time though, and even longer before the majority of browsers normal people use actually support the new standards.

This is very true. And these concepts of programming (languages) can be learned in basically any language. A programming environment that is supported by a large library of routines (functions, dat structures) is great in real life applications, but one has to program a (recursive) tree, linked list, smart sorting routine, etc at least once, to get some understanding of how powerful those libraries really are.

If somebody is coding these algorithms “to get some understanding of how powerful those libraries really are”, they are missing the point of coding these algorithms. Even PHBs easily understand how powerful libraries are… sometimes they even understand it too well. (That’s when they start hitting the vendor’s kool-aid too hard.) The hard part is to code elegantly and efficiently. That’s why it is worth sweating over reimplementing algorithms instead of relying on a library. Because eventually the library won’t be able to help you and at that time, if you have not learned to code properly, then you’re likely to end up with a mess on your hands.

That’s also why language matters. I’m sorry but languages are not all created equal and some languages lend themselves to intelligent programming more than others. For instance, in many languages, this is piss:

// Assume text is adequately declared and set...  I don't really care what kind of object it is.
boolean blah_flob;
if (text.startsWith("blah") && text.endsWith("flob"))
{
   blah_flob = true;
}
else
{
  blah_flob = false;
}

It should be coded as:

boolean blah_flob = text.startsWith("blah") && text.endsWith("flob");

Now, the sad thing is that there are languages for which the parser will not to directly set a boolean from the result of a boolean expression. People who learn those languages have to code the if… else… nonsense above. Let me be clear: their choice of language trains them to write code which in most languages is laughable. I can’t count the number of times I’ve seen an if… else… construct where it was not needed.

Thanks for the comments, everyone.

Well, I’ve looked a bit more into scripting InDesign and I think it really would be biting off more than I could chew, at least until I’ve got a grip on basic programming concepts. I may try tweaking some ready-made scripts to do exactly what I want, but I won’t bother trying to learn Javascript or the InDesign object model stuff in any depth for now.

I’ll go back to my original plan which was to learn a bit about programming, via Python. Lots of people, including many CS course designers and instructional book writers, think it’s a good language to start with. So there are some really good materials out there. I’ve already started working through Python Programming for the Absolute Beginner (a fun book which gets you writing some little games), and when I’ve finished that I’ll go onto Think Python (downloaded it a while back but realised I’d do better with an even easier book to start with).

Thanks to Brendon for the IRC tips–I’ll look into that.

Python 3.0 is out, by the way. It is probably better to learn it from a 3.0 perspective and adjust as necessary if you need to work with 2.6.

I think I have to disagree, for now. 3.0 is out but we haven’t caught up to it – the books and such are all aimed at 2.x, and the libraries haven’t been ported.

I’m still on 2.5 here, since package availability is better, and I don’t see myself moving to 3.0 for at least a year yet, possibly much more.

I think I have to disagree, for now. 3.0 is out but we haven’t caught up to it – the books and such are all aimed at 2.x, and the libraries haven’t been ported.

I’m still on 2.5 here, since package availability is better, and I don’t see myself moving to 3.0 for at least a year yet, possibly much more.[/quote]

Note what I did not say. I did not say “OMG !!!11!!!1! you shoudl forgat 'bout 2.6! do everthyng wiht 3.0 lol!1!!” I said “adjust as necessary if you need to work with 2.6.” I did not express a probability indicating whether or not this eventuality would in fact happen.

It is sensible to learn from a 3.0 perspective while keeping in mind what is needed to make things work in 2.6. Someone who knows what 3.0 allows and disallows can write 2.6 code which will be easily convertible to 3.0 when the time comes to convert. There are many changes which are of the form “in 2.6 you could achieve such and such result by method A or B, but in 3.0 you can only use method B.” So why not know that ahead of time, use method B in 2.6 code and not have to worry about the eventual transition? To take an example:

Why bother learning these methods if they are dropped in 3.0? It is possible to write 2.6 code which does not use them so why not start avoiding them now?

As for books, the only thing I ever used to learn python was the documentation they provide with the language:

docs.python.org/dev/3.0/tutorial/index.html
docs.python.org/dev/3.0/reference/index.html
docs.python.org/dev/3.0/library/index.html

And keep it simple !

Efficient programming requires that you fully understand (in advance) where your algorithm spends it time.
There is no need to in the code to replace number**2 by number * number because this executes faster, but solving the traveling salesman problem with brute force does need some thinking before implemented…