Element(element_id) vs getElementById in pyscript - pyscript

I couldn't find it on the docs properly, so can you guide in which case to use what in pyscript ?

You can use either. I prefer to use getElementById() and other native JavaScript functions as that provides an improved interface to the browser DOM.
getElementById() is a native function. That means there is well-written documentation on how to use the API and numerous articles on the Internet. Also, the entire JavaScript namespace (functions and variables) is imported into Python. By sticking with one namespace you are not switching back and forth between PyScript features that are wrappers for native features and just using native features.
IMHO the PyScript team is trying to develop an API just for PyScript. That is not hard to do, but I feel that API is not necessary and will hinder PyScript adoption. The JavaScript API works effortlessly in Python due to the bindings that the Pyodide team created. Pyodide is the engine that PyScript uses. 99% of the time, you do not even need the PyScript wrapper, you can directly run Python via Pyodide. I wrote an article on how to run Python code in the browser. The last section of my article shows how to create your own tags for Python. link If you are just getting started with PyScript review this link.
A JavaScript developer would not know what Element() does but will know what getElementById() does. The decision is up to you on which to use. I recommend learning both APIs and practicing with both. That way you can develop using everything available.

Related

Future of mirrors in Dart

I am developing an app in Dart and I plan to support dynamically loaded plugins. I can't do this in mirrors as it does no support instantiating classes from external sources, listing classes from external files etc. Do you plan to extend mirrors to support java like reflections?
Thank you, Skoky.
It was discussed several times but I think it is not decided. What was mentioned as argument against this feature is security which is taken very seriously especially in the browser but of course there are advantages and not having this feature limits the possibilties of Dart.
What you can currently do is launching additional isolates from external code files. This is currently cumbersome in the browser because an isolate in the browser doesn't provide access to not only the DOM but any browser API which is extremely limiting. But as I understand there are improvements planned or maybe already work in progress.

Is this correct : jquery is to javascript, django is to python?

I'm familiar with jquery and javascript but i'm a python noob. Whenever I learn something about python on the web, there's mention of django here and there. When i went to the official django site, it described it as "Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design." So I inferred it's what jquery is for javascript, am I correct?
[This might seem like a silly question but I tend to get shameless when it comes to asking questions on stack**overflow**]
I don't think it's a very useful comparison.
JQuery is mostly a wrapper around core functionality of javascript. Partly to make it easier to use and partly because otherwise you'd have to deal with browser specific problems even for the most basic scripts.
Django is a full-featured web framework that has many useful and necessary things built-in. It has request routing, templating, database abstractions, localization and a lot more.
In contrast to other web-frameworks it has those things tightly coupled and is opionated on what's the best practice to build your website with it.
A better comparison in the JavaScript world is (as an example) AngularJS. It also comes with lots of good features (routing, templating, data-bindings, dependency injection, etc.) but when you use it, you should better stick to "the angular way" of doing front-end JavaScript.
Think of JQuery more of a low-level library that you can build your code and even frameworks like AngularJS on. Kinda like the standard library of Python.
The short answer: Kind of- it is in the sense that JQuery is essentially a set of useful bits of code written in Javascript and Django the same in Python. However, JQuery is a more functional framework, where as DJango is more like a CMS framework.
No question is a silly question!
Almost, but not exactly.
I would say your python to javascript comparison is correct (as Python can be used as a scripting language for web applications, just like javascript), but jQuery is not exactly like Django.
jQuery is a library designed to simplify the scripts needed for dynamic website functionality, whereas Django is more useful in the creation of complex, database-driven websites.

GWT, Sproutcore or Cappuccino

I am about to start a new webapp that will be running on P/GAE and reagarding the front end we would like to use one of the mentioned frameworks (GWT, SC, Cap).
Which one do you think is the most developer friendly? It seems that Cappuccino looks stunning but you have to learn Obj-J. Sproutcore seems nicer (since there is only JS) but I could not say I am impressed with the docs plus some of the demos are broken.
GWT on the other hand is very mature but I have the feeling that using Java may slow you down as you cannot use some of the JS quirks on the other hand there is vibrant ecosystem around it.
I think the answer depends on what type of developer are you?
For me, I'm comfortable with Javascript and like the ability to manipulate the browser DOM so that I can implement features that may not be in the framework. That's why I prefer Sproutcore.
Checkout http://www.infoq.com/news/2009/09/sproutcore-1-0.
I have to agree with you that documentation is limited. However, I've found wiki useful and the community really helpful.
GWT is a very nice choice if you're using GAE-Java because then you can develop server-side and client-side in the same language. If you're using Python on the server-side, you won't be able to use GWT's simple RPC calls to serialize objects to/from the browser. It's still a nice framework though.
GWT does allow you to write JS-native code if needed, so you can "use some of the JS quirks" if you need to.
One warning: GWT apps are totally AJAX, so they can't really be seen by search engines (a general problem with AJAX, not with GWT specifically)

Google Closure Editor/WYSIWYG

Does anyone have experience with Google Closure Editor/WYSIWYG? I'm thinking of moving from CKEDITOR to Google Closure Editor/WYSIWYG. Ideally I'd love to use the etherpad editor but it doesn't appear that anyone has separated the editor from all the app.
Anyhow, for Google Closure Editor/WYSIWYG, does anyone know, does it support the real-time collaborative aspects seen in Google Docs?
The Google Closure editor is a wrapper around the built-in browser editing capabilities. It is thus similar to other rich text editors like TinyMCE, CKEditor, etc. It is less feature-rich than either of those, but it's smaller and faster. The base editor is used by Gmail (most notably) and various other Google properties.
There is nothing within the public Google Closure editor to enable Google Docs style real-time collaboration. With that said, it has a plugin model which enables you to add new functionality. I would not recommend taking something like this on without a solid understanding of working with Google Closure.
Until recently, the editor was also used by Google Docs. However, the limitations of core browser editing technology became a barrier to innovation, so they built their own editing surface[1,2] (codenamed Kix). This editing surface is not included in Closure Library.
https://drive.googleblog.com/2010/04/a-rebuilt-more-real-time-google.html
https://drive.googleblog.com/2010/05/whats-different-about-new-google-docs.html
It might not last, but there is a standalone version of kix up on github:
https://github.com/benjamn/kix-standalone
EtherPad Lite is the most viable option I've seen so far:
https://github.com/ether/etherpad-lite
Personally I favor this one, because:
It's open source
You can host your own
Has few server-side dependencies (Node.js)
It has an API, so you can build your app in any language
Attempting to steal Google's work is probably not a good long-term plan. (I'm also not convinced that having the client-side libraries actually helps you, in terms of the real-time collaboration feature, which depends heavily on the server-side.)

How can I do web programming with Lisp or Scheme?

I usually write web apps in PHP, Ruby or Perl. I am starting the study of Scheme and I want to try some web project with this language. But I can't find what is the best environment for this.
I am looking for the following features:
A simple way of get the request parameters (something like: get-get #key, get-post #key, get-cookie #key).
Mysql access.
HTML Form generators, processing, validators, etc.
Helpers for filter user input data (something like htmlentities, escape variables for put in queries, etc).
FLOSS.
And GNU/Linux friendly.
So, thanks in advance to all replies.
Racket has everything that you need. See the Racket web server tutorial and then the documentation. The web server has been around for a while, and it has a lot of features. Probably the only thing that is not included is a mysql interface, but that exists as a package on PLaneT (Racket package distribution tool).
UPDATE: Racket now comes with DB support, works with several DBs including mysql.
You may want to have a look at Clojure:
Clojure is a dynamic programming language that targets the Java Virtual Machine. [...] Clojure provides easy access to the Java frameworks, with optional type hints and type inference, to ensure that calls to Java can avoid reflection.
Clojure is a dialect of Lisp, and shares with Lisp the code-as-data philosophy and a powerful macro system.
Interop with Java is straightforward in Clojure, so you can re-use any existing Java libraries as you need. I'm sure there are plenty that are useful for web development.
clojure-contrib has an SQL API, and there is ClojureQL as well, which should cover your DB access needs.
There is a web framework for Clojure called Compojure under development. There may be others, too.
Clojure's source is available on github under the EPL. Getting it running on Linux is easy; I just clone the git repos and run ant.
You can do web development with guile scheme. Its standard library includes the (sxml simple) module that is very useful for html generation, manipulation, and parsing. The guile-www library adds support for http, cgi, etc. The guile-dbi library provides access to MySQL and other databases. With these building blocks, you can implement everything from simple cgi scripts to web applications with their own HTTP server.
Try Weblocks, a Common Lisp web framework:
http://weblocks.viridian-project.de/
I've written a pretty extensive tutorial/ebook on the topic: http://lispwebtales.ppenev.com/
Quick summary:
It uses Common Lisp
It uses the Restas framework
It has examples for pretty much most of basic web development, including DB access, authentication, HTML generation and templating.
Since the Restas documentation is pretty much out of date, my tutorial is the closest thing to up to date docs.
Shows a few of the more advanced features, like policies, which allow you to write pluggable interfaces, for instance you can write a data store layer, and write back-ends for different storage mechanisms with relative ease, the module system which allows you to write reusable components, like auth frameworks and things like that.
It covers things like installing lisp, setting up the ASDF build system and the quicklisp package manager etc.
It's free online, and as soon as I finish it it will be free on leanpub as well. The source is on https://github.com/pvlpenev/lispwebtales under a CC license, the source code is MIT. Not all of it is published yet, and I'm in the process of revising.
This may be what you are looking for.
http://www.plt-scheme.org/
http://docs.plt-scheme.org/web-server/index.html
http://common-lisp.net/project/cl-weblocks/
If you are interested in Common Lisp to be exact and do not want to go the weblocks route I would recommend the following setup:
Use SBCL on Linux but with multiple thread support
Use Hunchentoot as a web server which will provide you with all the server processing required including sessions and cookies
Use ClSql to communicate with MySql it has ample documentation and is very stable.
For the HTMl generation you can use Dr Edi Weitz Cl-WHO (very well documented).
Note all the above are under GPL or similar license (one that works more for lisp programs)
Gambit Scheme has its own solution to web apps as well. It uses the Spork framework, based o the Black Hole module system (both by Per Eckerdal).
Andrew Whaley has an initial tutorial on how to get Gambit, Black Hole and Spork running a web app under Apache using mod_proxy. You might want to take a look at that.
On a (possibly) related note, Gambit will also compile your stuff to C and then to an executable, if you feel so inclined.
Paul Graham (and friends) made a lisp dialect specifically for writing basic web applications. It's called Arc, and you can get it at arclanguage.org.
It's probably not suited for really big complex websites and I'm not sure what state it's database support is at but Paul Graham knows how to write web applications in lisp, so Arc will make the HTTP/HTML part easy for you while you spend most of your brain cycles learning the lisp way.
Weblocks is nice tool for building web apps in Common Lisp, but a bit too heavy-weight for me.
We use the following stack:
OpenMCL (open source Lisp, very nice)
Portable Allegroserve (web server, HTML generator)
Our own Rails-like tools for doing Ajaxy stuff (update: this has now been open sourced as WuWei)
A variety of CL libraries like cl-json, cl-smtp, md5
I use my own, customized version of Scheme, derived from MzScheme. It has a new, simple web-application framework, a built-in web-server (not the one that comes with MzScheme) and ODBC libraries. (http://spark-scheme.wikispot.org/Web_applications). The documentation may not be exhaustive, as this is more of a personal tool. But there are lots of sample code in the code repository.
Clojure is a Lisp dialect which may interest you. At this point there's a pretty decent web development stack. I can recommend a few things:
The leiningen dependency manager which makes is really easy to install and manage libraries that you're using. Pretty nice set of plugins for it too. There's even a plugin for Clojurescript, which is a language based on Clojure that compiles to Javascript.
The ring HTTP server abstraction. Its used in most actual web frameworks. Its a pretty good idea to learn that first before jumping into an actual framework.
hiccup is a HTML dsl/templating language written in Clojure. Its very expressive! Reminds me a bit of Jade, in a sense.
composure would have to be the most popular web framework for Clojure. Its essentially a routing library like express.js.
Let's see what can be done with Common Lisp.
The state of the Common Lisp ecosystem (2015) and the Awesome Common Lisp list show us a couple of modern frameworks (Caveman, Lucerne, all built on the new Clack web application server, an interface for Hunchentoot and other servers). Let's discuss with our own findings.
update 2019: there's a new tutorial on the Common Lisp Cookbook: https://lispcookbook.github.io/cl-cookbook/web.html It covers routing, template engines, building self-contained binaries, deployment, etc.
update: a bit later, I found out Snooze, by the creator of Sly or Emacs' Yasnippet, and had a much better impression than say Caveman. Declaring endpoints is just like declaring functions, so some things that were tedious in Caveman are obvious in Snooze, like accessing the url parameters. I don't have much experience with it but I recommend checking it out.
update june 2018: also don't miss the ongoing rewrite of Weblocks, it's going to be huge ! :D http://40ants.com/weblocks/quickstart.html Weblocks allows to build dynamic webapps, without a line of Javascript, without separating the back and front. It is components-based, like React but server-side. It's very alpha as of writing (june 2018), but in progress, and it's working, I have a couple simple web apps working.
A simple way of get the request parameters (something like: get-get #key, get-post #key, get-cookie #key).
I found easier the Lucerne way, it iss as simple as a with-params macro (real world example):
#route app (:post "/tweet")
(defview tweet ()
(if (lucerne-auth:logged-in-p)
(let ((user (current-user)))
(with-params (tweet)
(utweet.models:tweet user tweet))
(redirect "/"))
(render-template (+index+)
:error "You are not logged in.")))
Caveman's way has been less clear to me.
Mysql access
Caveman advertises database integration (with Fukamachi's Datafly and sxql).
You can just use clsql or the Mito ORM: https://lispcookbook.github.io/cl-cookbook/databases.html
HTML Form generators, processing, validators, etc.
I don't know if there are form generators out there. edit: there are: cl-forms and formlets, or again 1forms, working with Caveman2.
Caveman does not have one (issue raised in 2011).
Helpers for filter user input data (something like htmlentities, escape variables for put in queries, etc).
Ratify is an input validation library, not integrated into a framework though.
FLOSS and GNU/Linux friendly: ✓
Other web stuff
Speaking about web, there are other nice libraries in CL land:
web servers: Woo is a fast HTTP server, faster than Nodejs (beware of charts…), wookie is an async http server,
Dexador is an HTTP client
Plump, lquery and CLSS make it easy to parse html and query the DOM.
cl-bootstrap offers twitter-bootstrap shortcuts for the cl-who templating engine (which kind of replaces Jade/Pug, even though we have usual templates too).
Ajax in Lisp
(remember, with Weblocks, see above, we might not need those)
With ParenScript, we can write JavaScript in Common Lisp, without living our usual workflow, and we can thus use the fetch web API to write Ajax calls.
Clojure would be perfect for this. With some very short, clean code, you can implement some very complex applications, such as blogs or forums.
You might want to consider the awful web framework for Chicken Scheme.
Natively supports PostgreSQL and SQLite
Built-in easy support for sessions
Shortcuts for some webdev idioms, like the (ajax) procedure
Your app can be easily compiled to a static executable (via csc -static) for easier deployment
The collection of all chicken libraries (eggs) isn't as versatile as in some other programming languages, but isn't awful either