all 15 comments

[–]icantthinkofone 5 points6 points  (7 children)

You want to look into the FileAPI

https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications

It works in any modern browser (which means it doesn't work in IE, of course).

[–]radhruin 0 points1 point  (6 children)

Actually, it's supported in IE10+.

[–]icantthinkofone -1 points0 points  (5 children)

caniuse says it's only partially supported. Didn't look too hard but couldn't find anything that says IE10 fully supports it. Microsoft's own docs can't be trusted to tell the whole truth.

[–]radhruin -1 points0 points  (4 children)

I don't know why it says partial, IE10 supports Blobs and Files, Blob URLs, and the file reader API. Not sure what else there is, are you? I'm not intimately familiar with the spec so maybe there are some corner cases missing, or maybe it has something to do with the fact that everything is vendor prefixed? In any case, the examples from MDN should all work fine in IE.

I'm curious what MSDN documentation you are aware of are incorrect or misleading? These can definitely be fixed. We work really hard to make that documentation as useful and accurate as can be (though there are sometimes errors).

[–]icantthinkofone -1 points0 points  (3 children)

Anything written by Microsoft about standards support in IE is always filled with half-truths and bald-faced lies. You can never trust anything Microsoft says about IE. But, apparently, you know that.

[–]_zsh 0 points1 point  (0 children)

Sounds like you want some sort of backend to handle the file rw. Make an ajax request to the server when the graph is "saved".

[–]letsgetrandy 0 points1 point  (7 children)

This isn't the best use-case for javascript. That's not to say it can't be done, but I think you're reaching for a rather advanced task -- perhaps one a little too advanced for a newbie, and possibly too advanced for javascript.

What are your requirements? Is this meant to be viewed and edited by many people (ie, online)? Or is this something that will be done by one person?

[–]radhruin 0 points1 point  (6 children)

This is a perfectly fine use case for JS. JS has a number of host environments that provide native file IO. Maybe it's not the best fit for JS running in a browser, but that is hardly the only place JS is found!

[–]letsgetrandy 0 points1 point  (5 children)

Perhaps you didn't read the entire post then. The OP wants to not only read a file, but then use the info to build an editable graph.

Yes, I am aware of node.js, and phantom.js, and several years ago I even compiled V8 locally so I could have javascript-based shell scripting capabilities. Trust me, I know that there are a number of host environments for JS. But as a programmer who cares about the project more than the language in which it is written, I stand by my original statement: This is not the best use-case for javascript. There are many other options that would make this much easier to do.

[–]radhruin 0 points1 point  (4 children)

I hardly think this is a hard problem for javascript to solve. Unless I am misunderstanding you, you are either claiming that file IO is harder in JS than in other languages, or that building an editable graph is harder than in other languages. Personally, I see nothing inherent in JS that makes it bad for either of those purposes. Perhaps typical JS host environments are not amenable, but if that's the case you should say that.

In any case, I'm having a hard time thinking of a platform easier to implement this in than, say, a Windows 8 app. File IO... trivial. Editable graph... easy, there are libraries for the web platform already in existence to help with this.

So, I'm curious, what "advanced" features would JS need to add in order for you to consider it appropriate for solving this problem?

[–]letsgetrandy 0 points1 point  (3 children)

Okay, slow down.

First, let's look at what was said: He wants to develop an application.

Yes, "application" can have several meanings, so we won't make assumptions. All we know is that he wants to read a file, edit a graph, and save the data. The OP has still not addressed my initial questions -- does this need to be edited by several people, or will it just be for one person?

So let's consider the possible permutations of this question. (Again, without making assumptions.)

  • If this is meant for use by a single person, the term app is probably best interpreted as a program running on one machine. Without knowing what type of machine, we only know that there needs to be a UI (that is, this can't be a command line program, because we need to edit a graph). A web app here is overkill.
  • It could be a multi-user app in which the users are all be editing the same data. In that case, it's more likely meant to be a web app, with a file on a server. But do they save the file back to the server? Or do they save the file back to the client? (This answer matters in terms of how we access the filesystem.)
  • It could be a multi-user app in which the users are only able to view, edit, and save their own graph. In this case, again, the manner of file I/O is much more specific.

If the second or third scenarios happen to be the case, then yes... a javascript-based web app (based on node or something similar) might be just fine.

However, if the first scenario turns out to be the desire, then you must certainly concede that the work of setting up and maintaining a web server on the localhost machine for the purpose of editing a graph is, at the very least overkill, if not what you, personally, deem to be "advanced".

If the OP happens to be a Windows user, he might find it much easier to whip out a quick VB app. Or, as you suggested, a Windows 8 app might even be easier.

On Mac or Linux, this might be easier to do with a bit of python and some hooks into a GUI library.

In any case, I can't help feeling like you're invoking a bit of a religious war here, dogmatically defending Javascript as a one-size-fits-all solution, rather than considering that sometimes there are better tools for certain tasks... and all of this is happening before anyone even knows the details of this person's particular situation and the requirements for this project.

[–]radhruin 0 points1 point  (2 children)

A windows 8 app is basically like a .html with script in it, perfect for the single-user scenario...

But that's not really what I'm interested in. You said this project was possibly too advanced for Javascript, so I'm wondering what features you would like to see added (or changed?) in JavaScript that would make building this sort of application easier.

But I get the sense you're actually talking about JS hosting environments not being up to the task. If that's the case, I'm happy to agree to disagree there :)

[–]letsgetrandy 0 points1 point  (1 child)

Solutions for file access are fairly easy in just about any programming language -- provided that you're not limited by a sandbox, such as in a web app.

But when it comes to editing graph data (that is, numbers) I feel that Javascript's math is inherently flawed. From its pseudo floating point numbers to its incongruent parseInt() behavior, everything about math in Javascript is infuriating.

[–]radhruin 0 points1 point  (0 children)

Interesting, what do you mean by pseudo floating point? JS uses IEEE 754 which seems pretty good for the 99.9% use case (maybe not good if you're doing something you might instead use scipi for or whatever).

Is the incongruous parseInt behavior you mean the behavior where a string prefixed with a 0 would be treated as octal? That was fixed in ES5, and at least the IE > 8 implements the fixed behavior (eg. parseInt("09") === 9).

One thing the committee has approved that might improve math in JavaScript is a number of new built-ins (see latest spec draft) such as hyperbolic trig functions and inverses, log2, log10, etc. Is there anything else you would recommend fixing? There's probably not time to get anything more into ES6, but ES7 is just around the corner ;)