News for hackers. Stuff that matters.
Re:Ask HN: Is web programming a series of hacks on hacks? by 9point6 on Monday September 12, 2016 @08:15AM (#12479013)
I think your use of "minimum" is wrong here. If you're using React running on Node and Webpack as your task-runner you just need Javascript and that's it.

Node allows you to run isomorphic JavaScript that runs on both your server side and client side (to ensure you don't end up with the Angular-style skeleton pages coming from the server), You can pick a nice ORM (like sequelize) to abstract away SQL, and Webpack allows modules to specify their styles in JavaScript to allow compossible CSS for each given page.

Yes this is still using a couple of frameworks, but I personally prefer the approach of a lightweight standard library to the everything-and-the-kitchen-sink approach that other languages have.

Re:Ask HN: Is web programming a series of hacks on hacks? by zeveb on Monday September 12, 2016 @10:40AM (#12480036)
> Node allows you to run isomorphic JavaScript that runs on both your server side and client side

But then you're writing JavaScript on the server side, and I think I'd rather shove live weasels down my trousers than write one line more of JavaScript than I absolutely must.

Re:Ask HN: Is web programming a series of hacks on hacks? by BinaryIdiot on Monday September 12, 2016 @04:45PM (#12483487)
JavaScript is a fantastic language. I don't get this animosity towards it. A decade ago it was made fun of by people who "use real programming languages" but JavaScript has grown up. It's actually very good and very fast. ES6 brought improvements but honestly ES5 is still a great language.
Re:Ask HN: Is web programming a series of hacks on hacks? by nathan_long on Tuesday September 13, 2016 @11:04AM (#12488887)
JavaScript is not a fantastic language. It does a lot of things that make no sense. It converts between types in nonsensical ways. Eg in Ruby, you can't accidentally do `5 + "hi"` and get "5hi". If you really want to treat the number as a string, you can do `5.to_s + "hi"` and it works, but you don't do such crap accidentally.

In JavaScript, `4 / "cake"` returns `NaN`, which is sensible, but if I wanted to check whether I just accidentally did a bad division, `(4 / "cake") === NaN` will lie to me.

There are LOTS of quirks like this. JS is like a floor with boards missing all over the place. Yes, if you've walked on it every day for years, you've already stepped in every hole and know where they are. But that doesn't make it a good floor.

A good language is consistent. JS is not.

The fact that it now has fast implementations has nothing to do with it. This car goes 300mph, but don't use the left turn signal on Tuesdays because that sucker will blow you up.

Re:Ask HN: Is web programming a series of hacks on hacks? by BinaryIdiot on Wednesday September 14, 2016 @02:55AM (#12494708)
> It does a lot of things that make no sense. It converts between types in nonsensical ways. Eg in Ruby, you can't accidentally do `5 + "hi"` and get "5hi". If you really want to treat the number as a string, you can do `5.to_s + "hi"` and it works, but you don't do such crap accidentally.

Uh, so two things here. First, even though it's a dynamic language you should know what your code is doing. Your code should never be be "accidentally" doing this. That would be very poor design outside of an accidental bug.

Second, some other dynamic languages do this or other weird type coercion (I mean type coercion exists for a reason; sounds like you're against it in general which is separate from JavaScript). PHP simply extracts numbers from strings and uses them in this case. Many languages use + as a concatenation operator JavaScript just doesn't have a good way to override it so it could work properly in all cases.

> In JavaScript, `4 / "cake"` returns `NaN`, which is sensible, but if I wanted to check whether I just accidentally did a bad division, `(4 / "cake") === NaN` will lie to me.

It's not lying to you; you're using a feature of the language wrong. That's like calling the wrong validation function and getting upset because it's not working like you wanted it to (because there is a validation function for NaN). At the same time a good design won't run into this issue anyway. Now I'll admit NaN is a bit of an oddball so yes it's not the most intuitive but at the same time don't say the language is lying to you.

> There are LOTS of quirks like this. JS is like a floor with boards missing all over the place. Yes, if you've walked on it every day for years, you've already stepped in every hole and know where they are. But that doesn't make it a good floor.

> A good language is consistent. JS is not.

Not really. This is the common statement repeated by those who don't use JavaScript and consider it an awful language. If you're following best practices I'd love to know where all these language quirks or inconsistencies are because I'm for sure not running into them.

Re:Ask HN: Is web programming a series of hacks on hacks? by peterfoldi on Monday September 19, 2016 @12:48PM (#12532773)
NaN is not equal to NaN by the IEEE 754 standard. JavaScript, and many other modern languages, implement floating point numbers by this standard. E.g. in C#:

> 0.0/0.0 == Double.NaN

false

Re:Ask HN: Is web programming a series of hacks on hacks? by talyssonoc on Tuesday September 13, 2016 @06:34AM (#12486847)
Totally agree. The lack of understanding of JavaScript's paradigm from some people make them blind about the language power, it has the enough amount of every needed paradigm there, including OOP, functional and evented. I see in the comments here people complaining about things like dynamic `this` when they just don't understand it's one of the biggest powers of JS.
Re:Ask HN: Is web programming a series of hacks on hacks? by scriptkiddy on Tuesday September 13, 2016 @11:58AM (#12489456)
JS is not object oriented. A prototype is not the same thing as an object. There are no classes in JS.
Re:Ask HN: Is web programming a series of hacks on hacks? by renku on Tuesday September 13, 2016 @05:14PM (#12492316)
What you mean to say: JavaScript is not class-oriented.

Sure, there are features that JavaScript lacks compared to other object-oriented languages, but saying that it's not object-oriented is like saying that it's statically typed. It's just wrong, the language is full of objects.

Re:Ask HN: Is web programming a series of hacks on hacks? by talyssonoc on Monday September 26, 2016 @07:33AM (#12580939)
Ok, tell me where on "object-oriented programming" is the word "class". Objects are not necessarily related to classes. And yes, a prorotype is a object that you can extend from, as well as from any other object, like prototype-based OOP works.
Re:Ask HN: Is web programming a series of hacks on hacks? by dandv on Monday September 12, 2016 @02:12PM (#12482162)
JavaScript sucked indeed. ES6 though, has brought many improvements, and the language now is quite decent. With the advent of async/await in ES7 (which is available now if you transpile with Babel), the callback hell is completely gone, and the language is actually beautiful, powerful, and concise.
Re:Ask HN: Is web programming a series of hacks on hacks? by Fire-Dragon-DoL on Tuesday September 13, 2016 @03:02AM (#12486120)
I think we are exaggerating here. Javascript was terrible but with es6 it's just getting better, I know various languages and only Javascript manages to make me scream with its quirks, the others at most I feel disappointed. So "good" is an exaggeration, reasonable seems fine, but currently is either an OOP language where 'this' changes every time, or a functional language without native support for immutability, curried functions by default and a whole bunch of utilities that you expect from a language claiming to be functional. If it's a language with both mixed, must be compared to ruby which has consistent oop and functional programming with support for laziness and a super powerful ability to create dsl.

And in Javascript, it's still a nightmare importing a file. You either have a or you are on nodejs.

Re:Ask HN: Is web programming a series of hacks on hacks? by talyssonoc on Tuesday September 13, 2016 @06:24AM (#12486802)
Damn, I see so much frustration from you for not being able to understand JavaScript here... once you understand it's a different language instead of trying to write your favorite language with JavaScript syntax it'll get better, buddy, relax :)
Re:Ask HN: Is web programming a series of hacks on hacks? by eyelidlessness on Monday September 12, 2016 @12:20PM (#12480992)
You could of course write something that compiles to JavaScript. There's a ton of options, some are even pretty nice (I like ClojureScript; want to try out Elm).
Re:Ask HN: Is web programming a series of hacks on hacks? by gjolund on Monday September 12, 2016 @01:41PM (#12481837)
Elm is client side only.
Re:Ask HN: Is web programming a series of hacks on hacks? by goatlover on Monday September 12, 2016 @01:51PM (#12481943)
Elm can be installed run from the command line.
Re:Ask HN: Is web programming a series of hacks on hacks? by mLuby on Tuesday September 13, 2016 @01:20PM (#12490337)
Do you mean there's a way to run non-html-anchored Elm? Links would be wonderful!
Re:Ask HN: Is web programming a series of hacks on hacks? by sotojuan on Tuesday September 13, 2016 @10:26AM (#12488502)
Then use PureScript.
Re:Ask HN: Is web programming a series of hacks on hacks? by jensvdh on Monday September 12, 2016 @12:56PM (#12481379)
This is where Typescript comes in. It's beautiful.
Re:Ask HN: Is web programming a series of hacks on hacks? by bschwindHN on Monday September 12, 2016 @12:21PM (#12481005)
> You can pick a nice ORM (like sequelize)

I'm gonna stop you right there. Node is a helpful tool and I enjoy using it, but Sequelize was nothing but pure pain when I used it. You're much better off running raw SQL, or using a query builder like KnexJS.

I would never use Sequelize for more than a 1-table read or update.

Re:Ask HN: Is web programming a series of hacks on hacks? by tracker1 on Monday September 12, 2016 @02:39PM (#12482439)
honestly, in JS/Node, I find it easiest to use a SQL adapter that can handle template strings as parameterized queries...

    const results = await sql.query`
      SELECT ...
      WHERE foo = ${bar}
    `;

    if (!results && results.length) return;
    await myQueue.add(results);
Which works unbelievably well... There's not nearly as much need for boilerplate/translation layers in what is already a dynamic environment. I wrote a wrapper for ms-sql when migrating data, it took 2-3 days to get it done, but writing queries as above was so easy to work with it was incredibly nice. I'd rather work with a db that has a friendlier API to work with or abstract around... but writing a little template driven sql is often better than layers of boilerplate like an ORM.. and I still don't really get mongoose.
Re:Ask HN: Is web programming a series of hacks on hacks? by tonyarkles on Monday September 12, 2016 @05:44PM (#12483948)
Maybe I'm missing something, but that looks like SQL Injection ready to happen.
Re:Ask HN: Is web programming a series of hacks on hacks? by tracker1 on Monday September 12, 2016 @07:30PM (#12484524)
sql.query is a function that will receive two arrays, one is the strings part, the other is the injected values... the template processor takes those arrays and turns it into a parameterized query to the database.
Re:Ask HN: Is web programming a series of hacks on hacks? by tonyarkles on Monday September 12, 2016 @10:12PM (#12485180)
Very cool! In that example though... where's the array? And don't backticks do string interpolation?
Re:Ask HN: Is web programming a series of hacks on hacks? by sime2009 on Tuesday September 13, 2016 @03:37AM (#12486236)
Backticks by themselves will do string interpolation. But backticks with a function name in front will do something a bit different. In this case 'sql.query' is a function and the JS will pass it an array which represents the contents of the backtick string. There the function can do what it likes and return a result. 'sql.query' builds a proper (and safe!) SQL query and executes it.

The backtick feature in ES2015 is really cool and allows for some great DSL type features.

Re:Ask HN: Is web programming a series of hacks on hacks? by alxndr on Tuesday September 13, 2016 @11:47AM (#12489331)
This feature is apparently called "tagged template strings"; more on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re:Ask HN: Is web programming a series of hacks on hacks? by tonyarkles on Friday September 16, 2016 @08:42PM (#12518470)
Neat! Thanks for the awesome explanation!
Re:Ask HN: Is web programming a series of hacks on hacks? by bschwindHN on Monday September 12, 2016 @10:20PM (#12485212)
That looks fantastic, I'll take that any day over an ORM in JS.
Re:Ask HN: Is web programming a series of hacks on hacks? by tracker1 on Tuesday September 13, 2016 @11:08PM (#12494005)
Here's the one I wrote for mssql[1], though it should really be updated, and probably use tedious directly, instead of mssql.

[1] https://www.npmjs.com/package/mssql-ng

Re:Ask HN: Is web programming a series of hacks on hacks? by meredydd on Monday September 12, 2016 @08:20AM (#12479036)
I still count three frameworks :)

(React, Node, sequelize, I'm not counting webpack but I probably would if it's anything like as much of a pain as Grunt or Gulp or... And as you say, this is the lightweight version.)

Re:Ask HN: Is web programming a series of hacks on hacks? by frostymarvelous on Monday September 12, 2016 @10:03AM (#12479724)
And how many frameworks can you count in a win forms or wpf application?

If we're going to count frameworks, there'd be no end it. As I once said, programming is abstraction upon abstraction.

Like an onion, a Russia doll or better still, inception.

Frameworks abound everywhere, at every layer. You just need to adjust your scope as you see fit, to find them.

Re:Ask HN: Is web programming a series of hacks on hacks? by soundwave106 on Monday September 12, 2016 @11:23AM (#12480476)
Honestly from the programmer's perspective, it's really just one framework: .NET. I know that .NET abstracts away other frameworks such as the Win32 API, but generally you don't need to know any Win32 API etc. to make a Winforms / WPF / etc. application. With modern "web application" style development, it seems these days you need to know multiple frameworks by default, for better or for worse.

More to the point, .NET was designed from the get go as an enterprise programming language. The web was not designed from the beginning to be a universal application platform, it was designed to display formatted hyperlinked text. Much of the hack-y feel of today's web development -- as well as other aspects such as the rather poor security -- springs from this. If the web were designed from the get-go to be a universal sandboxed application platform, I feel that many things (ranging from the scripting language choice to the DOM model) would have looked a lot different today. Standard, non interactive HTML + CSS (what the web was designed for) certainly doesn't feel too hacky after all.

Re:Ask HN: Is web programming a series of hacks on hacks? by Fire-Dragon-DoL on Tuesday September 13, 2016 @03:12AM (#12486147)
I'm not sure what sre you talking about, if you program with c# and wpf, you need to know xaml and their weird syntax, you need to know prism which is a framework to properly organize your UI, you need to know a server language like asp. Net if you want to deal with backend code.

Prefer winform? That's much like react without using jsx, and if yoy want fancy graphics is much more complicated than html. Now sure you can stick to system style, but you can also buy css themes, use bootstrap, material ui frameworks to have your already prepared ui in html too.

Same issues with qt libraries... The thing is simple: inevitably you need more layer of complexity if you need to be able to maintain the code while being open to changes.

For simple apps, sure winform is faster, for complex apps, no way, it's the same.

And you can't really say that.net is a single framework when it includes so much stuff that is bigger than react, node, webpack, css and html put together

Re:Ask HN: Is web programming a series of hacks on hacks? by soundwave106 on Tuesday September 13, 2016 @12:36PM (#12489892)
I would have to disagree on the last sentence -- there is nothing in any definition of a software framework I know about that suggests that a software framework cannot encompass more than one function. .NET indeed does have a much larger solution stack then most web frameworks, for better or worse (there are advantages and disadvantages to this approach). But that does not disqualify it from being a framework in my opinion.

Web programming is more fragmented in nature, for better or worse. I think that was more my point with the first paragraph (and also a response that most .NET programmers don't need to care too much about any backbone frameworks .NET was built on). .NET provides you with a full front-to-back ecosystem. With web applications, you usually chose, at minimum, some form of Javascript framework, some back end framework, and some form of style framework. (Full stack frameworks for some reason have not taken off in the web ecosystem.) Even that description simplifies some of the fragmentation, due to the bewildering amount of choice. If you want to implement a Flux pattern in React for instance, there are over a dozen versions out there to chose from.

I don't think this necessarily says anything about app complexity or speed of development at all, agreed. Complex apps are going to be the same. I do think that the current fragmented, churn-y nature of the Javascript ecosystem can be a barrier to entry for simple apps at the moment; for that reason, I'll welcome the day when the Javascript ecosystem reaches peak "Javascript fatigue", becomes a bit more stabilized.

Re:Ask HN: Is web programming a series of hacks on hacks? by Fire-Dragon-DoL on Tuesday September 13, 2016 @01:20PM (#12490340)
True it's a single framework, my point was only the size... I mean, the amount of knowledge you need is probably the same you need to work with web stack.

Also, if you need a backend even if it's written in same language, is still a different thing, much like node and web javascript. Choosing a different backend languages usually is made because of the advantages it brings (Rails for prototyping, Erlang or Elixir for stability, Java for performance and so on)

Re:Ask HN: Is web programming a series of hacks on hacks? by atoko on Monday September 12, 2016 @02:45PM (#12482501)
You are confusing .Net, C# and WP* frameworks. .Net is closer to the JVM, C# is the language and WP* are libraries that interact with w32 apis
Re:Ask HN: Is web programming a series of hacks on hacks? by rpeden on Tuesday September 13, 2016 @09:52AM (#12488201)
Not trying to be pedantic, just posting to set the record straight:

- WPF, WinForms, ASP.NET, ADO.NET etc. etc. are all officially part of the .NET Framework.

- WPF doesn't do much (or any) direct interaction with Win32. It uses Direct#D for rendering.

- The CLR is the .NET equivalent of the JVM.

It's useful to look at the .NET Framework the same way as the standard library that ships with the JVM. They're both large standard libraries that include GUI Library (AWT, Swing, JavaFX, Winforms, WPF), database access (JDBC, ADO.NET).

In both cases, the extensive standard library can easily be used by multiple languages (i.e. VB, C#, F# in .NET, Java, Scala, Clojure and many others on the JVM).

Re:Ask HN: Is web programming a series of hacks on hacks? by Fire-Dragon-DoL on Tuesday September 13, 2016 @10:14PM (#12493813)
As rpeden pointed out, it's you that are confusing the things. CLR is what JVM is for C#, while all the stuff I mentioned are inside the .net framework
Re:Ask HN: Is web programming a series of hacks on hacks? by 9point6 on Monday September 12, 2016 @08:26AM (#12479079)
Ah I wouldn't count Node as a framework as I'd equate it to the JVM in Java world. But you are right, I'd probably lump webpack in there as it does have a fair bit of depth to it if you want to get the most out of it.
Re:Ask HN: Is web programming a series of hacks on hacks? by aclsid on Monday September 12, 2016 @09:32AM (#12479487)
You still need to use Express or something similar on the server side for Javascript, I mean, if we are talking about standard procedures here. Plus with React, you are still doing that Javascript/CSS thingy and HTML of course at some point, so there is no avoiding that, and clearfixes, polyfills, etc, etc.
Re:Ask HN: Is web programming a series of hacks on hacks? by tracker1 on Monday September 12, 2016 @02:34PM (#12482386)
But all of these things you're bitching about combined are far smaller than even ASP.Net without including anything client-side.
Re:Ask HN: Is web programming a series of hacks on hacks? by tracker1 on Monday September 12, 2016 @02:32PM (#12482372)
Node is a runtime, not a framework/language, and if you use a JS friendly DB (there are many with transparent APIs available (rethinkdb, mongo, etc) then it's all just JS.
Re:Ask HN: Is web programming a series of hacks on hacks? by nameless912 on Monday September 12, 2016 @11:04AM (#12480281)
I would argue that React is different enough so as to almost be called its own language. After all, it does use "JSX", whatever the hell that means ;-)
Re:Ask HN: Is web programming a series of hacks on hacks? by tempodox on Monday September 12, 2016 @09:27AM (#12479451)
> ... to abstract away SQL

SQL already is an abstraction, why would I want to abstract it away? Why not abstract JS away instead?

Re:Ask HN: Is web programming a series of hacks on hacks? by frostymarvelous on Monday September 12, 2016 @10:06AM (#12479749)
Well, everything is an abstraction, down to zeroes and ones.
Re:Ask HN: Is web programming a series of hacks on hacks? by dooptroop on Monday September 12, 2016 @11:19AM (#12480447)
Oh, it goes so much further down than that.
Re:Ask HN: Is web programming a series of hacks on hacks? by goatlover on Monday September 12, 2016 @12:37PM (#12481176)
It's all just fluctuating fields in the vacuum?
Re:Ask HN: Is web programming a series of hacks on hacks? by jethro_tell on Monday September 12, 2016 @12:03PM (#12480845)
Turtles all the way down.
Re:Ask HN: Is web programming a series of hacks on hacks? by tracker1 on Monday September 12, 2016 @02:41PM (#12482461)
Until you're working on a project where the turtles eat the errors...

Funny story, that's how I've been describing the issue with how errors have been handled on the project I'm working on, where there are SO many areas where errors are just ignored... so they don't propagate up the chain/stack... doubly annoying in a node environment where it's all supposed to be error first (as in the first thing you think about and check for).

Re:Ask HN: Is web programming a series of hacks on hacks? by tracker1 on Monday September 12, 2016 @07:29PM (#12484512)
I was describing the problem as "turtles all the way down, except the turtles are eating all the errors, and the rabbits can't find them"
Re:Ask HN: Is web programming a series of hacks on hacks? by ethagnawl on Monday September 12, 2016 @11:15AM (#12480393)
> Why not abstract JS away instead?

Lots of projects are already doing this: Elm, ClojureScript, PureScript, etc.

Re:Ask HN: Is web programming a series of hacks on hacks? by gjolund on Monday September 12, 2016 @01:40PM (#12481831)
"thats it"

250mb worth of dependecies later...