最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How similar are Python, jQuery, C syntax wise? - Stack Overflow

programmeradmin2浏览0评论

I'm trying to get a sense of the similarities between languages in syntax. How similar are Python, jQuery and C? I started programming in Actionscript 3 and then moved on to Javascript , then went on and learned Prototype, and then I started using jQuery and found that the syntax is very different. So is jQuery more like C and Python?

I'm trying to get a sense of the similarities between languages in syntax. How similar are Python, jQuery and C? I started programming in Actionscript 3 and then moved on to Javascript , then went on and learned Prototype, and then I started using jQuery and found that the syntax is very different. So is jQuery more like C and Python?

Share Improve this question asked Sep 1, 2010 at 4:54 ChamilyanChamilyan 9,42310 gold badges39 silver badges68 bronze badges 4
  • 7 jquery isn't a language. It uses javascript syntax throughout. If you don't understand this, then maybe you need to review your javascript. – aaronasterling Commented Sep 1, 2010 at 4:56
  • jQuery isn't a language. "jQuery syntax" is Javascript syntax. I think you already know that, but I don't think it's all that fair to pare one language's syntax to the coding/api style of a framework in another language. Apples and oranges and stuff. – Cristian Sanchez Commented Sep 1, 2010 at 5:00
  • Ok, I understand the jQuery isnt a language. Thats not really what I was saying but it came out that way. I meant jquery packages things differently and you call on things differently then from Javascript plain and Prototyped enhanced Javascript. – Chamilyan Commented Sep 1, 2010 at 5:25
  • no, you don't call on things any differently with jquery than with regular javascript. And if you know what you're doing, you package everything up in closures and as object attributes just like jquery to avoid polluting the global namespace. Again, I think you need to review javascript. – aaronasterling Commented Sep 1, 2010 at 6:24
Add a ment  | 

3 Answers 3

Reset to default 8

C is much different from the languages you've asked about. Remember that C isn't an interpreted language and will not be treated as such in your code. In short, you're up for a lot more material to learn --while dealing with C-- in terms of things like memory management and semantics than the other languages.

In regards to syntax: You'll find that if you're writing code in any language other than Lisp, brainfuck, or some other non-intuitive language (not claiming that C is, but in parison, certainly), the syntax isn't too much of a variable. There are some differences, but nothing that should be considered too abstract. In C, you have to worry about things like pointers and whatnot which is a pain, but I think the difference is more-so about memory management than syntax. You mostly have to worry about the differences in usages of semicolons and whatnot.

You'll find that Python is like writing English sentences, or at least writing pseudocode with constraints, which makes it significantly easier than C. Additionally, I wouldn't consider jQuery a language on its own. It's an extension of a language though, just as STL might be considered a particular type of extension to C++.

Good luck.

Syntax wise, JavaScript (the language jQuery is implemented in) is similar to C. Python uses a different syntax which does not rely on semicolons and braces, but instead on indentation.

Semantically, JavaScript is closer to Python, so this would be easier to learn. I don't understand how you "moved" from ActionScript 3 to JavaScript to Prototype; ActionScript has the same syntax and is also otherwise very similar to JavaScript, and Protoype/jQuery are just applications written in JavaScript (so it's the same language, but different frameworks!)

For jQuery, the answer is pretty simple: jQuery isn't a language, therefore it doesn't have syntax.

For Python and C, the answer from a high-level point of view is also very simple: Python's syntax is directly inspired by C's syntax. (Or more precisely, both Python's and C's syntax are inspired by ALGOL's syntax.) There is really only one significant difference from a high-level point of view: C uses opening and closing curly braces to delimit blocks, Python uses indentation.

Otherwise, the two high-level syntaxes are almost the same: both have unary and binary operators, even with similar precedence (unline Smalltalk, for example, which doesn't have operators), both distinguish between statements and expressions (unlike Ruby, for example, which doesn't have statements), both use semicolons between statements (although technically, the semicolon is a statement terminator in C and a statement separator in Python), both use similar syntax for numeric literals and string literals as well as array/list indexing.

There are a couple of syntactic differences related to the different semantics: in Python, variables are untyped (only objects are typed), so there is no type annotation syntax for variable declarations (in fact, there is no syntax for variable declarations at all). There is syntax for type annotations of function parameters and function return values, but in Python the types e after the parameter name, and the type annotations are optional. With variables being untyped, the concept of type casting doesn't make sense, so there is no syntax for that. Neither is there any pointer-related syntax, since Python doesn't have those.

Python has a couple more literals than C: lists, sets, dictionaries, in particular. However, they follow in the C tradition: in C, an array is declared and indexed using square brackets, so Python uses square brackets for array literals.

发布评论

评论列表(0)

  1. 暂无评论