5 ms·
Python in the browser would ultimately lead to all the same problems as Javascript in the browser. In a few years, we'll be hearing: Clojure in the browser, Sca
by tomp 15y ago
Python in the browser would ultimately lead to all the same problems as Javascript in the browser. In a few years, we'll be hearing: Clojure in the browser, Scala in the browser, Haskell in the browser.
I've been programming in Python full-time for the past 6 months, and it's main deficiency are the same as JavaScript's: no (optional) static typing - I'm really sick of writing checks whether my function got values of the correct types, and unittests testing if a class's/function's signature changed in an unexpected way.
What we need, in my opinion, is a dynamic language with powerful optional static typing (unlike Dart, where types are just comments), with sane object-orientedness, and support for immutable values. The core has to be really simple, but the language has to be powerful enough so that libraries can provide the missing functionality (math - rationals, matrices, ...; concurrency - channels, isolates, ...; GUI, IO (with formats, ...)).
- jimhefferon 15y agoSomeone has already achieved Clojure. https://github.com/clojure/clojurescript https://github.com/clojure/clojurescript
- icebraining 15y agoWhen they mean "X in the browser", it's being natively supported. Python-to-JS exists too: http://pyjs.org/ http://pyjs.org/
- Joeboy 15y agoI'm a bit unclear, but I think they mostly mean "bytecode in the browser".
- cploonker 15y agoI do agree that we need a language with static typing so that one can have some level of confidence before releasing the code to production. Having said that python definitely is much better than javascript.
- rufugee 15y agoDoesn't dart actually do type checking? It's been a month or 2 since I played with it, but I could swear that it did type checking and reported errors when the type was wrong.
- rst 15y agoIt has a "checked mode" and an unchecked mode, but they recommend the checks be disabled in production. The unchecked mode is actually called "production mode" in a lot of their documentation, including the language spec. (See the section on "types".)
- ma2rten 15y agoI also prefer typed languages. I also don't like, the way classes are implemented in Python (the whole self thing). But I think Python has enough good stuff to make up for it. To a degree this is psychological, if you only focus on the bad stuff, you will end up hating every programming language you work with.
- gbog 15y agoThe self thing is one of my favourite feature in python, it is then shoo easy to refactor a method in a function, it makes very clear where things come from, etc.
- dripton 15y agoI sometimes see C++ code where all the member variables start with "m_". I'd much rather have it enforced by the language than in a coding convention. (I personally find Ruby's explicit "@" prefix for member variables prettier than Python's explicit "self.", but that's minor.)
- mhansen 15y agoFYI, Dart does type checking. If you want to give your javascript some type-checking, try running it through the closure compiler. This is what we do, and we annotate our methods with type signatures like this /** * Queries a Baz for items. * @param {number} groupNum Subgroup id to query. * @param {string|number|null} term An itemName, * or itemId, or null to search everything. */ goog.Baz.prototype.query = function(groupNum, term) { ... }; And then the Closure Compiler tells us if we've broken some type contracts.
- tomp 15y ago> FYI, Dart does type checking. According to the official docs [1], it does not: They have no effect whatsoever in production mode. Dart does, indeed, have a "checked mode" in which types are checked (I wasn't aware of that before). In any case, Dart's type system is inconsistent (like Java's), intentionally, but I still don't think I could be called "static". [1] https://docs.google.com/document/pub?id=1RqcfL64kw5SJkyut6eN34d7YYMy4EXZ0nNuTn1kmBZg#h.7tlgp5n9j12w https://docs.google.com/document/pub?id=1RqcfL64kw5SJkyut6eN...
- jamesgeck0 15y ago> I'm really sick of writing checks whether my function got values of the correct types That doesn't sound like a problem that you should be having. The "Pythonic" way to do things is just roll with the values you get and handle any errors that result.
- Pewpewarrows 15y ago> I'm really sick of writing checks whether my function got values of the correct types, and unittests testing if a class's/function's signature changed in an unexpected way. Sorry to be blunt, but if every one of your Python functions and methods begins with isinstance() checks for every parameter, you just missed the point of the entire language. Python was built on a foundation of ducktyping, with the mantra that "it's easier to ask forgiveness than permission" (EAFP). Just use your parameters in whatever way you expect them to be, and either catch the rare Exception there or allow them to bubble up. Here's some suggested reading on the subject: http://www.canonical.org/~kragen/isinstance/ http://www.canonical.org/~kragen/isinstance/ http://stackoverflow.com/questions/6092992/why-is-it-easier-to-ask-forgiveness-than-permission-in-python-but-not-in-java http://stackoverflow.com/questions/6092992/why-is-it-easier-...
- tomp 15y agoNot every function, but often enough that it gets annoying. It mostly happens when dealing with very tight systems, e.g. a RabbitMQ queue consumer fetching messages from an external system and writing stuff to MySQL & Cassandra. The general issue is that there are some kinds of data types (integer, string, datetime) that cannot really be duck-typed, i.e. replaced by different objects. In my experience, it is better to catch such type errors sooner rather than later, therefore isinstance() checks.
- haberman 15y agoThe Python approach means that when an exception is thrown, it's unclear whose fault it is. Is it a bug in the called function, or in the caller for passing a bad parameter? The larger the program the more of a problem this becomes. It also means that when you change a function signature, the compiler can't tell you all the call sites you need to fix. You have to find them through testing. This is a large barrier to aggressive refactoring. Even the Python C API provides facilities for checking that arguments have a specific type and raising TypeError if not, so it can't be that completely counter to the intention of the language: http://docs.python.org/c-api/arg.html http://docs.python.org/c-api/arg.html (see O!)
- 15y ago
- halayli 15y agoIf you are checking your parameter types then you haven't used python enough.
- tybris 15y agoOnce you master GWT you can really be very productive in it, while allowing you to: -Write statically-typed code -Maintain large projects using packages and OOP -Use unit testing, code generation, and refactoring tools -Use many Java libraries out-of-the-box or with minor modifications (this part I often find mind-boggling) -Write code that works on server and client (also mind-boggling) -Ignore the DOM, just use widgets -Ignore the vast majority of cross-browser issues -Get great IDE support -Readily deploy apps in servlet containers like GAE or Elastic Beanstalk -Get very performant, minimized production code -Get help implementing best practices such as safehtml -Interleave with JavaScript Main drawbacks are that there are few well-maintained widget libraries, compiler takes forever, Google has been a bit reluctant to expand JRE emulation, and the script format is a bit annoying. Java is also not a great asynchronous language since it lacks anonymous functions. However, if slightly uglier looking code really concerns you, you probably don't have your priorities straight. I don't really know what the point of Dart is. I suspect it is being promoted more out of legal concerns over Oracle than out of technical merit.
- tsewlliw 15y agoI'm constantly on code reviews for and occasionally writing GWT code, and the gymnastics and ceremony it requires on top of the slow compilation are painful enough, and the resulting JavaScript/html unpredictable enough, that I would refuse to work on any new project that used it. It's just a tool that makes your existing HTML/CSS/js knowledge useless, a crutch for java blubs.
- dkersten 15y agoPython in the browser would ultimately lead to all the same problems as Javascript in the browser. In a few years, we'll be hearing: Clojure in the browser, Scala in the browser, Haskell in the browser. Did you miss this bit of the article: "Web browsers can be viewed as a zero install interface, a virtual machine for these applications. Such a VM has no reason to be language dependent." I don't think the article is really about Python, just thats used as an example because that's the language the author uses. I think its really about wanting a VM in the browser that any language can compile to (without having to compile to a high level language like javascript).
- deleted 15y ago[deleted]
- stcredzero 15y agotldr: capabilities you want already exist in languages. Non-mainstream stuff to check out for the curious. What we need, in my opinion, is a dynamic language with powerful optional static typing...with sane object-orientedness, and support for immutable values. The core has to be really simple, but the language has to be powerful enough so that libraries can provide the missing functionality Check out Strongtalk. I know it already has almost everything you just mentioned above: http://www.strongtalk.org/ http://www.strongtalk.org/ * optional static typing - Check! * sane object-orientedness - Check! - superlative, actually * the core...really simple - Check! * language has to be powerful...libraries can provide the missing functionality - Check! I'm not sure if it has immutables, but VisualWorks Smalltalk has it, so it is feasible to add it. (Especially since the engineer who added it for the private vendor is now working on Cog, which is an open source VM.) In addition, Squeak/Pharo run with a >bit-identical model< on something like 50 platforms. (Including different ISA, not just OS.) That's an ideal capability for a browser language. I'm not saying that we need to use a derivative of Smalltalk in the browser. Smalltalk doesn't have operator precedence, so it comes across as strange to lots of technical people. In fact, lots of things are elegantly different in a lateral-thinking weird way. Alan Kay said it best: the computer revolution hasn't happened yet -- it is in progress. It takes decades for the full impact of what comes out of research labs to really reach the mainstream. It's time for some far-sighted people to take stock of capabilities we're not aware of yet, but which are there to be used.