BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

The Pi as a development platform

Sun Dec 28, 2014 5:38 am

I've been looking at Django and I've got it running on a Pi with the help of this Github project. I'm still going through the "Writing your first Django app" tutorial now but it seems to me it's up to the task I'm considering it for.

I got to thinking that if one created a disk image with Django and a project pre-installed then developers would have a consistent platform to develop on with a well documented and supported framework that they could use their favorite tools on. For me, that would be BBEdit and few other apps on a Mac.

I've been developing my own web apps with my own framework for a couple years now on the Pi and this has worked great for me. I can still work when my internet connection is down, and since I live in a rural area that's still pretty common. I can test my work on my wife's iPhone and Windows tablet, and my Mac and Android phone, over our wifi LAN. And since my apps are deployed on a Linux VPS I only have to make a few changes to paths in a setup file to run them on my production server.

It seems to me this approach has some pretty big advantages. You could have a team spread out in diverse locations all working mostly offline on the exact same platform which could make "telecommuting" a much more efficient process than it has been previously (as far as I know).

Now, since I'm almost never the brightest bulb in the chandelier I suspect this is either being done, or there's good reason it's not, so any feed back that sheds light on what I don't know is welcome.

Heater
Posts: 14776
Joined: Tue Jul 17, 2012 3:02 pm

Re: The Pi as a development platform

Sun Dec 28, 2014 8:13 am

BillStephenson,
....if one created a disk image with .... pre-installed then developers would have a consistent platform to develop on with a well documented and supported framework
Very true. All most no one would use it though as we all have our own idea of what we want on our Pi SD cards. However if you do have a team working on a particular project then such a base image of the project makes sense.

...I suspect this is either being done...
Yep. In the wider world of web development the issue of development and deployment on known consistent base lines has been getting a lot of attention recently. This is especially important for those constantly spinning up and taking down cloud servers, like Google and FaceBook etc. It's important for those who want their projects to be usable across any cloud provider of virtual machines. Say I want to host on Google Cloud, or Amazon, or MS Azure.

The solution is "containers". Pretty much like your disk image idea. A "container" holds all your apps code plus all the dependencies it has, the frame work, the libraries, etc etc, The container can be moved around and run anywhere.

Seems the most popular container system right now is "Docker". You can read about it here: https://www.docker.com/

As for Django. No thanks. I never want to have to write code that looks like that below. Give me node.js, express and react.js.

Code: Select all

<h1>{{ question.question_text }}</h1>

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

<form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
{% for choice in question.choice_set.all %}
    <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
    <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
{% endfor %}
<input type="submit" value="Vote" />
</form>
Last edited by Heater on Tue Jan 06, 2015 12:10 pm, edited 1 time in total.
Memory in C++ is a leaky abstraction .

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Mon Dec 29, 2014 12:07 am

Thank you for the informative response!

I really couldn't agree more about that ugly code. That seems convoluted and messy to me.

I also looked at "Flask", but it uses a similar method of mixing code in view templates. Am I wrong in thinking that this is pretty much the opposite of a MVC design approach? I know it gives me headaches when I try to unravel a site built this way by someone else.

Code: Select all

{% extends "layout.html" %}
{% block body %}
  {% if session.logged_in %}
    <form action="{{ url_for('add_entry') }}" method="post" class="add-entry">
      <dl>
        <dt>Title:
        <dd><input type="text" size="30" name="title">
        <dt>Text:
        <dd><textarea name="text" rows="5" cols="40"></textarea>
        <dd><input type="submit" value="Share">
      </dl>
    </form>
  {% endif %}
  <ul class="entries">
  {% for entry in entries %}
    <li><h2>{{ entry.title }}</h2>{{ entry.text|safe }}
  {% else %}
    <li><em>Unbelievable.  No entries here so far</em>
  {% endfor %}
  </ul>
{% endblock %}
Give me node.js, express and react.js.
Hmm... I haven't really looked into any of those. I honestly thought node.js was a client side library like prototype.js. I'm almost sure I've seen it used that way, but on the site it looks more like a server side JS runtime engine, similar to Perl or Python. Am I wrong about this?

If that's the case that's pretty funny because years ago I tried to talk the Perl foundation into creating a Perl runtime for web browsers and they thought I was crazy. It's never made sense to use two languages to code a web app, but I suppose it makes more sense to have a JS runtime on the server side. Back then JS was giving me headaches so I didn't use it much until the prototype libraries came out. These past couple years I've been using JS a lot more though, and it's impressive now, even without using 3rd party libraries the built-in runtime engines are solid and the API is rich.

I do want to try and catch up with what's working now. I'm fine with using Perl on the server side, but if node.js can do much the same thing I'd use it instead. It would be great to be able to write code in one language for both the server and client side of an app and it seems that most web app developers really hate Perl.

I tried installing node.js, express and react.js on a Pi but ran into some glitches with express, which I'm pretty sure were self induced. I had that disk image pretty gummed up already though so I'm making a new one and starting over.

And I played with Docker too. Now that's certainly interesting. I haven't made it so far as to see a real app made on it, but I'll keep looking into it.

Thank you again for all the info. I'm pretty sure you've push me at least 2-3 years ahead of where I was this morning :D

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Tue Dec 30, 2014 1:18 am

I started working my way through a few of the lessons at http://nodeschool.io/. While I was playing with that I ran across this lesson: "Learn about CouchDB - the database that completely embraces the web".

Node.js with Express, React, and now CouchDB. That pretty much cinches it for me.

CouchDB looks like exactly what I've been wanting, but way better, and using one language (JS) for both the client and server has been something I've wanted for a very long time. Sucks for me it wasn't Perl, but I've spent enough time with JS these past couple years to know I can work with it, and I'll get better.

Honestly, I am pretty much stunned by both of these developments.

Heater, I have to thank you again. I would not have understood or found all this if you hadn't taken the time to point me in this direction.

Heater
Posts: 14776
Joined: Tue Jul 17, 2012 3:02 pm

Re: The Pi as a development platform

Tue Dec 30, 2014 10:35 am

BillStephenson,

Node.js is server side. Basically it is the V8 JavaScript engine, as used in Chrome, made usable on the command line. It's kitted out with a ton of interfaces for accessing networking, filesystem and a lot of other stuff. Then there are tens of thousands of "modules" that have been written for it to do almost anything imaginable.

It's pretty amazing. Despite being JS it is fast. I have server side processes recreated in node that were previously C++, they run nearly as fast as the native compiled C++ and a much less code to write and much easier to maintain, extend and modify.

You can of course do similar with Python, django, or probably Perl etc, but the results will be slower and more complicated. Also JS programming is all asynchronous. That means no messing with threads and the problems they cause programmers. It means performance is very good when dealing with many simultaneous network connections.

JavaScript is actually a sophisticate language providing features that other languages are only just now thinking about, first class functions, lambdas, closure etc. JS is is not just that simple scripting tool for browsers, one should take time to learn it properly.

Be careful with Docker. It requires a recent Linux kernel to work properly. I forget what the minimum version reqired is so do check that.

I too am stunned by all these developments. Being an old school embedded systems engineer I have only been messing with "web stuff" recently. Well apart from a stint writing PHP a decade ago. Things are so much better than those of PHP/Apache/MySql days.

I now have super fast 3D data visualizations animated with webgl in the brower (Love the THREE.js and Ivank.js libraries for that), server code in cloud servers in JS with node and now JS in the remote embedded systems as well. All communicating via websockets (Love socket.io for that). It's JS everywhere!

The big problem is that my old brain can't keep up. There are dozens of libraries and frameworks for web development. Dozens of databases to choose from. Every time I search around for a solution to a problem I run into 10 new things I have never heard of before. There is not enough time to find out about and evaluate them all.

Just now I'm fixated on the following:

Node.js, Express, Passport, Bootstrap, React, Socket.io, THREE.js, Ivank.js, MQTT, etcd, Docker. Nginx for front end proxy/load balancer. Yeah, we still use MySql!

It's probably time to look into coreos for those cloud services. Oh and zeromq is looking attractive for messaging.

If you want to see a stunning development tool for node.js have a google for "nodered". Works on the Pi just fine.
Memory in C++ is a leaky abstraction .

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Tue Dec 30, 2014 7:36 pm

I know this is long winded, but I just have to say it....

When things started going to PHP/SQL (LAMP) I looked into it and was just floored by how fast a web app got tangled up into a mess almost impossible to unravel if you didn't make it yourself, or if you left it alone for a few months and came back to it.

Instead, I decided to use CGI.pm's built-in "Save" function to save data into files. My theory was that since the app was designed to know where the data file was located using Perl's built-in calls to open and load a file into a CGI object it was easier than wiring up an SQL database, and that added way too much complexity to make it worth the supposed benefits it offered.

I named the data files using an epoch timestamp and a unique number (1103165701-1005.dat). This was so I could load just the file names into an array and quickly find those in a user defined time range, put them in a list, and open those one at a time and test if they matched the data the user was looking for. If they did I grabbed the data and added it to a list, closed the file and open the next one. My tests with it showed this to be very fast in the use cases that were relevant to my app. And I could create my own data relationships very easily in perl. I didn't need to use a 2nd language and a 3rd party database engine. I didn't need to worry about security issues with those either.

I argued that SQL database engines were designed to solve problems that were being obsoleted by advances in hardware and software. Specifically, limits in the number of files, limits in RAM, limits in storage space, and limits in processor speed. Most everyone dismissed me as not knowing squat, and there's some truth in that, but someone chimed in about how my flat file method uses the OS's native B-Tree file system and that is indeed very fast.

Later on I mention that I had devised a method to update a large CGI file for an app I made. When I uploaded the changes over my slow internet connection my app would break for those using it until the upload was complete, so I made a script to upload the file with a different name and when the upload was complete I use a system call to copy the new file over the original. My question was rather or not this would also break users that were working with the app or cause any other issues, like corrupting data. Someone chimed in and told us that this made the change "at the atomic level", and that my users wouldn't be affected at all.

These things, though I really still do not understand them entirely, were enough to convince me I was doing fine and the LAMP stack users could keep their "M". I didn't need it.

So way CouchDB is described in the node school lesson really floored me. It is basically these same things that the CouchDB does different than SQL. The difference between JSON and CGI.pm's data formats are logical in design, but not significantly different in how they're used by an app or stored/accessed by the database.

So I am just stunned. Honestly, what I was doing now looks a whole lot smarter to me, and all this time I'd been thinking I was just too dumb to know better. Moving to this new framework will be easy for me. I understand it because it works like I want to work. It's like it was made just for me! :lol:

Heater
Posts: 14776
Joined: Tue Jul 17, 2012 3:02 pm

Re: The Pi as a development platform

Tue Dec 30, 2014 9:00 pm

I agree, the "web stack" has been crazy.

Take a simple thing like displaying a table of data. Rows an columns. Basically you have to generate a pile of HTML text, table, table column and table row elements for the browser to render. You could have:

a) A program that just spat that out given the data content to fill into the elements. You know, like printf. That is tedious and inflexible so you end up with:

b) An HTML template with place holders for the data that gets filled in by some template engine.

c) Worse still an HTML template with place holders that contain PHP or other language that fills in the data.

It's just horrible.

Whilst you are at it that PHP within the template will make some SQL queries to fetch the data it needs. Oh, and you will need some CSS to make it look nice. Oh and how about throwing some regular expressions in there?

Before you know it you have 5 or 6 different languages syntax all mixed up in the same source code. Blech! And your data and presentation are intimately bound together. A maintenance nightmare.

Oh I forgot, you might want that PHP to stuff some JavaScript in there for the browser to run whilst you are at it!

Things are not looking much better even with all the new funky frameworks and JS doing all the work in the browser instead of generating all HTML on the server.

But, I do like the idea that: The browser gets the page, the JS writes out the structure, the server just needs to deliver the JSON required. Now at least we have separated the data from the display some what. New frameworks like Angular and React go this way. I like React for it's simplicity and speed.

I would not be so dismissive of SQL. It does what it does very well. What it does is maintain a lot of tables and the relations between those table entries. It allows you to make very complex queries on that data. It maintains consistency and all that ACID stuff.

That's great if you are a bank. It was great when I was part of a team creating a web store back in the late 1990's. Turns out a lot of applications don't need all that rigorous ACID stuff and having it makes it hard to build scalable, flexible, fault tolerant and fast systems.

As an example I'm working on a project now that hoovers up tons of data. Needs too store it as fast as possible and needs to allow queries of it based on time or geographical location. Thing is once you have a data item it never changes, it's a record of history, a log, immutable. All of a sudden all that data consistency stuff is not required. Data can be split over many machines by geographic area. There is no relation between them. An SQL data base can choke on this. Much simpler systems do not.

Seems you were right and the new generation of web developers is now catching up with you!

I have no idea about CouchDB. Guess I should check it out.
Memory in C++ is a leaky abstraction .

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Tue Dec 30, 2014 10:15 pm

Well, what I was building are document based applications. (http://www.ezInvoice.com and http://www.foxdesk.com). As I was reading more of the docs on CouchBD the example they give for the "Why" in using it is a document based web invoicing application :D

My issues with using SQL are all mine, I know that. I was overwhelmed so fast by all these parts of the stack that I had to toss some of them aside and put off others, and I made my excuses for doing so. One of the replies I got in response to my discussions was that using SQL "Made it easy". That alone is a good reason to use it and I can't argue against it when it's true. But that doesn't mean my excuses were all invalid either.

It is interesting to see how these things have evolved. I mean, finding a database designed specifically to handle data like I was wanting to do back then is just one of those little miracles of the internet that astound me. Even more astounding is how much thought and work has been put into the design and feature set of CouchDB. It does stuff I hadn't ever thought about and now want to do.

The "Document" based design concept has merit, and CouchDB provides some powerful tools that allow it to be used in a lot of creative ways. I still have a lot to learn, but now I'm getting excited about framing up an app with all this and getting to work on it.

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Fri Jan 02, 2015 5:04 am

I've successfully installed and tested everything I wanted to get started with modern web application framework on a B+:

Node.js
Express.js
Express Application Generator
React
CouchDB

And I made a disk image so I can start fresh from there if I want too,

If anyone is interested I'll post the complete instructions with references here.

Heater
Posts: 14776
Joined: Tue Jul 17, 2012 3:02 pm

Re: The Pi as a development platform

Fri Jan 02, 2015 3:09 pm

BillStephenson,

Excellent, having been the one the suggested all that stuff to you I'm going to be trailing behind your progress.

My Christmas break has been all about trying to understand something of making a node/express app secure. Implementing login with user names, passwords etc. Dealing with XSS, CSRF, and other web vulnerabilities.

My demo of such a system is here : https://github.com/ZiCog/secure_express_demo

This has to evolve a bit further to be useful. So far it's just a login page. It needs HTTPS support, hashed passwords and a few other things before I am happy with it. See the TODOs in the code.

I intend to add a lot more comments and documentation to it, if only for future reference for myself in real projects.

Please do post your results up some place. I'm interested in how couchdb works out on the Pi.
Memory in C++ is a leaky abstraction .

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Fri Jan 02, 2015 9:00 pm

Here's where to find the step by step install I did on a B+

http://www.raspberryperl.com/pinode/Ins ... mework.txt

Heater
Posts: 14776
Joined: Tue Jul 17, 2012 3:02 pm

Re: The Pi as a development platform

Fri Jan 02, 2015 9:22 pm

Bill,

I love it. Totally ASCII instructions, simple and succinct.

Seems "raspberryperl" will now refer to perls of wisdom rather than Perl in future :)
Memory in C++ is a leaky abstraction .

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Mon Jan 05, 2015 12:34 am

Heater,

All I can say so far is "Wow!"

I spent some more time on Friday going over the app structure generated by the Express generator and the code in the default "app.js" file. I couldn't get far though because my wife had plans for me, but I got a couple hours further this afternoon.

After I figured I had a clue I started playing around a bit. First I made another "view" and added it to my routes file the way I figured I should be able to, and it worked. So then I thought I'd add a CSS class to a "p" tag (p.green") in my new view, and it did it again, it just worked! All I could think was "I'm not that smart, so the team that made this stuff must good."

The next big step for me will be to tie in the CouchDB to my app and learn how to start using it. I think I'll take the "Notes" app I have on the raspberryperl site and rewrite it with these tools. That will give me a chance to use React too, so it will be a fairly complete example of the web app stack in action.

Can we call this stack "NiCER"? (Node.js including CouchDB, Express, React)

It sure feels nicer to me. :D

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: The Pi as a development platform

Mon Jan 05, 2015 1:05 am

More frameworks, more stuff to learn. KISS.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Mon Jan 05, 2015 2:04 am

iinnovations wrote:More frameworks, more stuff to learn. KISS.
That's for sure. There are so many frameworks, too many. And there are a lot of things to consider when choosing one. It's an investment.

I'm not worried about the latest, greatest thing, but I do want what I go with to have forward momentum. In this stack we have Google, Facebook, and Apache projects backing them. Those first two have the resources to improve the technologies I've been using, and those I want to use.

This particular framework is by far the simplest I've evaluated. Tools like "Express" mostly do set-up work. The structure of an Express app is not so different than what I used in my perl framework, so I understand the flow of how it all works together, it makes sense to me. It saves work, standardizes the app structure, and adds some cool features that you're gonna need anyway.

I can already see how much Node.js does to simplify building a web app and I've barely had a glimpse of what's out there in the way of modules for it. I had no idea how much different this is than what's going on with Perl and Python until Heater pointed it out. I was looking only at Perl and Python frameworks but this is an much better way of doing things. Node.js is most certainly where web app building is headed, at least the kind I want to build. I have no about that now.

Now, "Node-RED", that's just cool. I have got to play with that now too. I'll get to all those Heater has mentioned, but that one jumped out at me and it looks like it will be a lot fun to play with, so I'm installing it now!

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: The Pi as a development platform

Mon Jan 05, 2015 2:45 am

I don't feel the same way about node. I also don't have a need for app routing in the way that so many new application servers now use. It's just unnecessarily complicated. It's elegant and flexible, but not necessarily intuitive, and very prone to obvious screw-ups, configuration snafus, and glaring security oversights.

In the end, you need css, html, js and a way of routing data to/from the server. All my server-side control code is python, so it makes sense to me to have this done in a gateway interface that's native to python -- wsgi. I already process my data into a lightweight set of databases for control algorithms which works great. Python has a native API for that too.

The above known, I really have to have a need for another framework to be willing to do the work, or see an obvious way it will streamline my coding, offer future flexibility, enhance features of the application and/or improve performance. jQuery is an obvious yes. A css/js/html framework like jQuerymobile, another obvious yes. node, however, addresses a problem for me that just doesn't exist, and comes with some significant caveats.

It's not that I'm averse to change. I will use whatever tool will do the job, even if it means stepping away from things I know exceptionally well. I was not satisfied with the ajax/wsgi response times I was getting, so yesterday I rebuilt my system with the uwsgi/nginx stack, foregoing the Apache/mod_wsgi that I know like the back of my hand and have been using, well, forever. It just has to do a specific job, do it well, and be worth the risk. Managing dependencies of a handful of new, constantly evolving technologies is not interesting or rewarding work. Getting my uwsgi/nginx configured properly for multiple application serving took me far longer than the analogous process on Apache, and with new things the 'Right Way to Do Things (tm)' often changes with each rev. Not even to mention security of known versus existing technologies ...

C
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Mon Jan 05, 2015 7:37 pm

I've always thought the "Pretty URLS" was gimmicky too, so that's sort of solving another problem I didn't think I had as well. That was brought up as a big advantage when I discussed it on some perl mailing lists. On the server side how those formats are interpreted should be handled by some kind of middleware, like CGI.pm has for me. I shouldn't have to do much but locate the data I need to format a response. I can screw up what I send from the client side just as good with most any format.

Node, as a project, is young, but like most it builds on others so it's not entirely new or especially susceptible to vulnerabilities. The recent Terminal vulnerability shows those can linger unnoticed for a long time almost anywhere.

I like my perl framework. It's familiar and I'm productive with it. But I've also been doing a lot more on the client side in JS and if node.js can allow me to code in JS on the server side with the same feature set as perl has offered, I'm not opposed to exploring that. I really like that concept.

The Perl community is pretty stuffy too. I was a member of several of their mailing lists for a long time and they were kind of mean to people. You had to pity a poor beginner who had the nerve to come ask a beginner's question there.

I've not messed with JQuery much yet. I'm ready to move on past Prototype, which is still a good library, but I've focused on writing my own code for the simple things I've had to do for the present just to get a better feel of things. I may end up using JQuery, but so far I've found a lot of what I want to do is easy to write a small script for without it.

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: The Pi as a development platform

Mon Jan 05, 2015 8:47 pm

BillStephenson wrote:I've always thought the "Pretty URLS" was gimmicky too, so that's sort of solving another problem I didn't think I had as well. That was brought up as a big advantage when I discussed it on some perl mailing lists. On the server side how those formats are interpreted should be handled by some kind of middleware, like CGI.pm has for me. I shouldn't have to do much but locate the data I need to format a response. I can screw up what I send from the client side just as good with most any format.
Pretty URLs are a weird reason to do anything. Any good server has rewrite.
I like my perl framework. It's familiar and I'm productive with it.
This, behind application features and performance, is the most important thing.
But I've also been doing a lot more on the client side in JS and if node.js can allow me to code in JS on the server side with the same feature set as perl has offered, I'm not opposed to exploring that. I really like that concept.
I don't. I think there is a tool for every job. Python libraries are ubiquitous and designed to do the server side stuff. Code snippets abound. Using JS on the server side just feels like using something familiar for that reason alone
The Perl community is pretty stuffy too. I was a member of several of their mailing lists for a long time and they were kind of mean to people. You had to pity a poor beginner who had the nerve to come ask a beginner's question there.

I've not messed with JQuery much yet. I'm ready to move on past Prototype, which is still a good library, but I've focused on writing my own code for the simple things I've had to do for the present just to get a better feel of things. I may end up using JQuery, but so far I've found a lot of what I want to do is easy to write a small script for without it.
jQuery isn't really something that takes time to learn. I spent time writing a bunch of DOM stuff in vanilla javascript before I met jQuery, and I'm really sorry I did. It's really where one should start when coding javascript. It makes clean, recognizeable code. It doesn't hide javascript. It enhances it. The methods are all very similar, but just better. Added error handling, DOM methods ... there's a reason more or less every good web code snippet on the tubes uses jQuery
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: The Pi as a development platform

Tue Jan 06, 2015 12:21 am

iinnovations wrote:Using JS on the server side just feels like using something familiar for that reason alone
For me the same is true for Perl or Python really, but all these languages have so much overlap that creating a runtime for JS on the server side makes perfect sense to me. I would offer that Node.js is being built almost specifically for web apps though, as are many of the modules that are available for it, so as opposed to either Perl or Python, that is the focus of the project.

As far as the web server component goes, Node.js works about the same as any other web server as far as I'm concerned. Express sets up an fairly robust app framework right out of the box. There are a lot of modules out there for Node.js, and I suppose many, if not most, are made specifically for web apps. These are pretty attractive features.

I went over to the JQuery web site and looked a little closer at it. It's been my intention to do that for awhile now. As I said, in the past I've used Prototype.js for some things, but I don't think it's as user friendly as JQuery. The documentation was never very user friendly anyway.

It looks to me that all you have to do is drop JQuery in the empty "javascripts" directory that Express sets up and call it in your view. It's pretty hard to not want to do that and your point about learning it from the start is a good one. It's almost certain that everything I'll want to do will be there waiting and already made easier for me.

I still have to look at React too. I'm not sure how that might overlap with JQuery, but it seems pretty focused on UI features, so there may be few if any overlaps, or it may work with it, but I don't think it's an either/or choice.

For me personally, I'm more productive in JS than Python. I do okay with Python considering I haven't spent a lot of time with it, but I'm slow. JS feels more "Perl Like" to me now and that's really the biggest attraction it has for me.

We'll see how I do with my little "Notes" app. If I can get through that pretty easily with this set up I'm sure I'll be fine.

Heater
Posts: 14776
Joined: Tue Jul 17, 2012 3:02 pm

Re: The Pi as a development platform

Tue Jan 06, 2015 8:52 am

innovations,
More frameworks, more stuff to learn. KISS.
Yes indeed. In my case the first web development I did was for a web shop over ten years ago. It was built with Linux, Apache, MySQL, PHP. (The famous LAMP stack). It was awful experience. All those files with HTML, PHP amd MySql commands all intertwined in a horrible mess. I could see no way to straighten it out. I hated PHP with a passion.

That was such a nightmare I stayed as far away from anything to do with the web for a long time.

Until recently we got a requirement for fast, real-time, animated visualization of streamed data in the browser. We needed websockets, we needed a websocket server. The first solution I stumbled across was node.js and socket.io. Boom, I had the demo up in a couple of days.

That opened my eyes to the fact that web development need not be that horrible complicated ugly mess I had seen before. In that project I did not even have to touch HTML or CSS. I did not need to brush up on my Python or PHP. It was JS end to end.

Now we have node running in embedded systems out in the field. JS is getting everywhere.

That's KISS for me.
Memory in C++ is a leaky abstraction .

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: The Pi as a development platform

Tue Jan 06, 2015 9:06 am

One can make anything ugly.

To make good customized web apps, you need to know css, html and js. Even with existing frameworks (I use jquerymobile, which is pretty damn plug and play), you need to tweak it to make it your own, and to tailor it to your app, using css. Or you may need to do rendering of data to UI elements: CSS, with jquery/js. Understanding layout, css and html. You just can't get around it.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

Heater
Posts: 14776
Joined: Tue Jul 17, 2012 3:02 pm

Re: The Pi as a development platform

Tue Jan 06, 2015 12:06 pm

Innovations,
One can make anything ugly.
Yes, but it's impossible to make that mess of HTML, MySql and PHP pretty. HTML by itself is ugly enough PHP adds the warts :)

I think there us some misunderstandings going on here...

node.js is not a "framework". It's just a run-time for the JavaScript language. It allows to type "node myapp.js" and have myapp run, in the same way you type "python myapp.py". One would not call a basic python set up a "framework". Nor many others like perl or PHP.

Being just a language run-time node has applicability in many other areas than just creating web sites or web applications. It is general purpose. We use it for all kinds of stuff all the way down to embedded ARM boards.

Then we come to things like the node Express module. I'm not sure I'd call that a framework either. It's just another module (library) that I pull in and use if I like.

I'm curious about how you don't need "app routing". Everything on the web works with URLs. RESTfull API's depend on them. How do you get by without routing? Admittedly Apache or other web servers do a lot of that for you but it's still there.

I agree that if one is going to write for the web, as web pages or the new fangled "single page app" style, one should get to know ones HTML and CSS and JS. This is where things get messy. As far as I can tell it gets messy no matter what language you are using on the server end. The browser API (HTML, CSS, DOM) is just horrible. Finding a neat way to meld all that together is tough. That is where the plethora of "web frameworks" come in. Seems everyone has their own different ideas how it should be done. Personally I don't want to waste my life evaluating and trying them all to find the optimal solution for me. I just hope that after looking around a bit my choice is going to at least work:) Currently that looks like it's going to be Bootstrap and React. THREE.js and IvanK for the accelerated data visualization animations. Socket.io for the real-time data streaming.

I'm interested in you comment re: "glaring security oversights". I know nothing of security and especially web security. But recently I was looking into how one might set about securing a node based web service. All of a sudden I run into acronym soup, XSS, CSRF, CSP, SSL... Most of this stuff seems to be about disabling browser and server behaviours that I've always though should not be there in the first place. Or at least not enabled by default.

I'd love it if someone like yourself would look over my humble attempt at creating a secure web app. Currently it's only a sign-up, log-in, log-out system with no actual functionality. It does not yet store password hashes in any database. It's very short. Perhaps you can see some obvious errors or omissions in there. I want to use this as a starting point for putting Pi based controls on line. It's here: https://github.com/ZiCog/secure_express_demo

Addendum:

What to you guys mean by "Pretty URLs" ?
Memory in C++ is a leaky abstraction .

User avatar
r3d4
Posts: 978
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: The Pi as a development platform

Tue Jan 06, 2015 1:29 pm

Heater wrote:Addendum:

What to you guys mean by "Pretty URLs" ?
My guess "Pretty URLs" mean Semantic (web) URL :?:

---
"fetchez la vache"!

Heater
Posts: 14776
Joined: Tue Jul 17, 2012 3:02 pm

Re: The Pi as a development platform

Tue Jan 06, 2015 1:37 pm

Ah yes, they do look nice. Why would anybody ever use non-pretty URLs ?
Memory in C++ is a leaky abstraction .

User avatar
r3d4
Posts: 978
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: The Pi as a development platform

Tue Jan 06, 2015 1:59 pm

Heater wrote:Ah yes, they do look nice. Why would anybody ever use non-pretty URLs ?
It could be that too much AI and not enough IA makes everyone use meaning-less URLs

Return to “General discussion”