HNHacker News
TopNewBestAskShowJobs

Longwelwind

248 karma · joined April 30, 2016

Blog: https://longwelwind.net LinkedIn: https://www.linkedin.com/in/fr%C3%A9d%C3%A9ric-kaczynski/

For enquiries:

frederic.kaczynski@gmail.com

submissionscomments
Longwelwind··on I love React Hooks
If I have this:

  <div v-for="item in items">
    <span>...</span>
  </div>
The refactoring tools must know that the "items" inside the "v-for" refers to a property of the data object. In other words, the content of the data bindings is a totally new language by itself (the content of v-for has its own syntax, with a parser).

Compared to the equivalent in React, which would be:

  {this.items.map(i => (
    <span>...</span>
  )}
Or possibly

  let elements = [];
  for (item in this.items) {
    elements = <span>...</span>
  }
It's way easier for a refactoring tool to support JSX since it's just syntactic sugar over JS. If you were the developer of such a tool, you would just need to consider "<>" as values and possibly consider anything inside "{}" as normal Javascript.

And indeed, as pointed by another commenter, React supports classes and integrates very well with Typescript since React 16.

Longwelwind··on I love React Hooks
If your project grows big, you will at some point need to use a state management library like VueX which has similar concepts than Redux, so I'm not sure this argument holds.

My biggest problem with Vue is the template syntax. Since JSX is a thin layer over Javascript, few modifications have to be done over Javascript (or Typescript) tools to make them work with JSX (or TSX). Vue templates are a totally new language which requires more complex tools. I've never had any problem using refactoring tools (renaming variables, go to declaration, find usages, ...) with React, while in my last Vue project, renaming a variable broke code.

Vue has Vuetify, which has been a breeze to use, though. I don't know if there is a React equivalent.

Longwelwind··on Hexagonal Grids (2013)
Your guide is the first thing I open in my browser every time I need to code an algorithm in a hexagonal space.

Thanks a lot for the amazing work!

Longwelwind··on Redesigning Redux
Can someone explain to me why someone would choose Redux over something like MobX ?

I feel like implements an action for each modification of state (or group of modifications) requires a lot of boilerplate code. In MobX, you treat your data tree as a separate entity, and simply modify it. The UI is automatically updated whenever it needs to.

Mobx isn't bad performance-wise, I think, since it only re-renders the components that are listening to the modified variables when a modification occurs.

The only advantage I see is being able to rewind the state store, which can be quite cool when debugging.

I have done some medium-sized application (only games), and I don't think I've run into any performance or readability problem with MobX. I've never done web apps with a team, though, but I don't think Redux would specially make it easier to work with other programmers.

Longwelwind··on How Bitcoin Compares to History's Big Bubbles
You could argue that:

* Bitcoin reached the price of 10k 2 months ago, at the end of November. The Bitcoin has only lost "one month" of its price, for the moment.

* There has been a dip in the price of Bitcoin every January for the last 3 years. It fell from ~1200 to ~700 in January 2017, for example.

I'm not saying that this is not the "final crash", just that what's happening for the moment isn't really surprising. I saw numerous people predicting that the price will fall at least back to ~8k.

Longwelwind··on Diminishing returns of static typing
Yes, of course !

https://jsfiddle.net/0wc0vjw2/1/

Longwelwind··on Vue.js vs. React
GP formatted it wrong, you could write the JSX example like this:

  return (
    <ul>
      {numbers.map((num, i) => (
        <li key={i}>
          {num}
        </li>
      ))}
    </ul>
  )
Which with syntax highlighting is, imo, as readable as any piece of code.

The advantage is that it is statically checkable with a linter, so you would get a compile-time error if you misspell the HTML tag, a variable or anything else.

If you use something Typescript, the compiler will even check the props given to components (and if you use VS Code, you'll get auto-completion for variables, methods, props and anything statically checkable). You can even apply inheritance to components for dynamic component switching.

I briefly used Vue before switching completely to React (with Typescript, Webpack and Mobx) and it finally became enjoyable to write Javascript applications.

Longwelwind··on An Introduction to Support Vector Machines
During the learning phase of the SVM, you try to find an hyperplane that maximizes the margin.

The decision function of an SVM can be written as:

  f(x) = sign(sum alpha_sv y_sv k(x, sv))
Where sum represents the sum over all support vectors "sv", "y_sv" represents the class of the sample (red=1, blue=-1, for example), "alpha_sv" is the result of the optimization in the learning phase during the learning phase (it is equal to zero for a point that is not a support vector, and is positive otherwise).

The decision function is a sum over all support vectors balanced by the "k" function (that can thus be seen a similarity function between 2 points in your kernel), the y_i will make the term positive or negative depending on the class of the support vector. You take the sign of this sum (1 -> red, -1 -> blue, in our example), and it gives you the predicted class of your sample.

Longwelwind··on An Introduction to Support Vector Machines
In the decision function of an SVM, you compute the scalar products of the support vectors (points that are on the margin of your hyperplane, or more precisely, the points that constrain your hyperplane) and your new sample point:

  x· sv
The "z" the article defines is a new component that will be taken into account in the scalar product. A more mathematical way of seeing that is that you define a function phi that takes an original sample of your dataset, and transform it into a new vector. In our case, we simply add a new dimension (x3) based on the two original dimensions (x1, x2) that we add as a third component in our vector:

  phi(x) = [x1, x2, x1² + x2²]
The scalar product we will have to compute in our decision function can then be expressed as (this is the a and b in the article, i.e. the sample and the support vector in our new space):

  phi(x)· phi(sv)
The SVM doesn't need phi(x) or phi(sv), but the scalar product of those two numbers. The kernel trick is to find a function k that satisfies

  k(x, sv) = phi(x)· phi(sv)
and that satisfies the Mercer's condition (I'll let Google explain what it is).

Your SVM will compute this (simpler) k function, instead of the full scalar product. There are multiple "common" kernel functions used (Wikipedia has examples of them[1]), and choosing one is a parameter of your model (ideally, you would then setup a testing protocol to find the best one).

[1] https://en.wikipedia.org/wiki/Positive-definite_kernel#Examp...

Longwelwind··on An Introduction to Support Vector Machines
I don't know if you are more familiar with matrix notation

  phi(x) = [x1, x2, x1² + x2²]
  phi(x)· phi(y) = [x1, x2, x1² + x2²]*[y1, y2, y1² + y2²]
  phi(x)· phi(y) = x1 y1 + x2 y2 + (x1² + x2²)(y1² + y²)
Longwelwind··on Principal Component Analysis Explained Visually (2015)
Machine learning (and more specifically here, supervised learning) is about predicting a specific attribute of a new sample, based on the attributes of the samples that you've acquired. For example, if you have access to the database of the clients of a bank, containing their attributes such as their income, their age, their occupation and whether or not the bank accepted to give them a loan, you may want to create a system that based on this database, can predict whether a new person will get a loan or not.

It happens that having too much different features is not necessarily a good thing, in a phenomenom called curse of dimensionality.

Due to this, we are interested in trying to reduce the number of attributes our algorithm will process. There are two big categories of methods to do that: feature selection and feature extraction.

In feature selection, you try to select the attributes that are the "best" to predict your value. For example, computing the statistical correlation between the attributes and the value you want to predict, and choose those with the highest correlations.

In feature extraction, you create new attributes that are a linear combinations of the original attributes. PCA is a feature extraction algorithm.

Longwelwind··on Angular 4.0.0 Now Available
Typescript with React is necessary for me. I feel like it highly increases my productivity when coding, and it makes it easy to refactor the code.

Plus you can do some cool things like Component inheritance.

I've never tried Flow, but I guess it's practically the same.

Longwelwind··on Programming won’t be automated, or it already has been
You can use Rice's theorem[1], which is a generalized version of the Halting problem.

I don't believe this proves that programming can't be automated, though. Humans too aren't able to prove completely that what they write is correct, it doesn't stop them from making programs.

[1] https://en.wikipedia.org/wiki/Rice%27s_theorem

Longwelwind··on Our long term plan to make GitLab as fast as possible with Vue and Webpack
React managed to make HTML "statically typed".

If I make a typo in the name of a component or the name of an attribute used in a HTML tag property, Typescript will catch it. Since Vue & Angular uses template strings, TS can't do the same check.

This makes catching errors and refactoring easier.

I used to prefer Vue, but since I've discovered Mobx, I only use React now. It took me a lot of time to properly learn the tools, but I'm pretty happy with them now.

Longwelwind··on If I could amend PEP 8
I believe it will be:

    def very_long_function_name(
        arg_one,
        arg_two,
        arg_three,
        arg_four
    ):
It's consistent and doesn't require spaces so it lets you use tabs to let the reader choose its indentation size.
Longwelwind··on Announcing TypeScript 2.1
Maybe it is me, but I feel like mapped types and keyof are terrible features, and using them would be a sign of a bad design/architecture.

In general, I don't think using a string that represents a static symbol (such as the name of a var, an attribute or a class) is a good idea.

I try to keep a simple stack (Typescript + NPM at the moment), and I prefer to wait for Typescript to have the feature I want, than to install a new dependency (Babel, for example) to my project.

Longwelwind··on If TypeScript is so great, how come all notable ReactJS projects use Babel?
Why not ?

I only see advantages for static typing for a small cost of time: you prevent most of Type Error from happening, you get automatic auto-completion, refactoring errors are easier to catch and feel safer. Either way, you need to specify the type of the arguments in the documentation of your function (I can sometimes even find the C# LINQ's function I'm looking for just by looking at the return type of the list of function).

You could even use Flow and Typescript to catch

Aside from the proprietary reasons (which I believe are unfounded since the whole Typescript ecosystem is opensource), why do you think static typing doesn't belong in Javascript ?

Longwelwind··on Instant.io – Streaming file transfer over WebTorrent
What kind of trade-offs ?

Genuinely interested, I know the basics of the torrent protocol, and I don't understand why the torrent protocol wouldn't work for streaming... I mean, you would just need to request the packets in order instead of randomly.

It would be less efficient, sure, but it would work.

Longwelwind··on Mathematical Notation Is Awful
>Two, wikipedia refers to E(X) and E(Y) as the means, not the expected value. This gets even more confusing because, at the beginning of the Wikipedia article, it used brackets (E[X]), and now it's using parenthesis (E(X)). Is that the same value? Is it something completely different? Calling it the mean would be confusing because the average of a given data set isn't necessarily the same as finding what the average expected value of a probability distribution is, which is why we call it the expected value. But naturally, I quickly discovered that yes, the mean and the average and the expected value are all exactly the same thing! Also, I still don't know why Wikipedia suddenly switched to E(X) instead of E[X] because it stills means the exact same goddamn thing.

IIRC, the mean is the particular case of the expected value where the transformation function is the identity function.

The general expression of the expected value, where f(x) is the probability density function and g(x) is the transformation function, is:

E[g(X)] = \int{g(x) * f(x) * dx}

Let g be the identity function (g(x) = x), then E[g(X)] is the mean.

For example, let's say that you bet on a throw of dice such than you win 2$ if the result is odd, lose 3$ if the result is 2, and win or lose nothing otherwise. Here, the event X is the throw of dice: you have 6 possible outcomes. Your transformation function is the gain you get for each outcome, therefore g(x) is defined by:

1 -> +2

2 -> -3

3 -> +2

4 -> 0

5 -> +2

6 -> 0

Then, the expected value E[g(X)] can be calculated by summing all the g(x) multiplied by the probability p(x) for all x (all outcomes).

The first point of the article, in my opinion, is more about statistics than math in general, and I believe people find it weird because of the confusion between X and x, the former being a random variable associated with a distribution function, the ater being a value in the domain of X.

The second point of the article is just ease of notation. The derivative of a function doesn't exist; a derivative is always made with respect to a variable (df/dx), but if a function has only one variable, then the derivative of the function is defined as the derivative of the function with respect to the one and only variable and we don't need to write this only variable (f'(x)).

You could always write the variables of a function (df(x, y, z)\dy instead of df/dy), but that's just a waste of time, specially when you have to write it for every line of the demonstration.

Longwelwind··on Ember.js 2.7 and 2.8 beta released
Thanks, I didn't know that Ember did more than just fetching the value.

About time wasted, I feel like in the long run, you gain more time by writing statically analyzable code. If you make a typo in the string, you would have to build/transpile+launch the code in order to see the error. Additionaly, if you ever refactor the name of the property, the linter will directly tell you that "value" in the lambda must be changed.

Longwelwind··on Ember.js 2.7 and 2.8 beta released
Over-reliance on strings is a pattern that I've seen a lot in the Javascript environment. For example:

  var arr = [{ value: 'a' }, { value: 'a' }, { value: 'b' }, { value: 'b' }];
  arr.uniqBy('value');  // [{ value: 'a' }, { value: 'b' }]
Wouldn't be better to do something like this ?

  var arr = [{ value: 'a' }, { value: 'a' }, { value: 'b' }, { value: 'b' }];
  arr.uniqBy(element => element.value);  // [{ value: 'a' }, { value: 'b' }]
You have to write a little bit more (I could have used "e" instead of "element", though) but if you do a typo in the name of the property, it can be caught by a linter/compiler, and you don't get the feeling you're relying on Vodoo magic.

Are there any advantages to use a string instead of a "static" way of accessing the property ?

Longwelwind··on John Carmack on Inlined Code (2014)
I'm not sure it should be considered as a reason for anything. The most important point of the article, imo, is:

  If a function is only called from a single place, consider inlining it.
You should consider inlining your function, not always do it. Recently, I made a mod for a game and I had to draw an UI by code, and there, it made sens to use one-time function because it made the code easier to read (super-expressive functions like DrawLeftPane() or DrawHeader(), and next to no ties between functions).

Most of the time, code readability should be prioritized over performance.

Longwelwind··on Build Your First Thing with WebAssembly
I believe "module" in classic Javascript already corresponds to a "self-contained" Javascript file.
Longwelwind··on What would it cost Apple to make iPhones in the U.S.?
I don't know why we want so hard to bring these jobs back (the same way we always try to keep the metallurgic industry in Europe).

These jobs are becoming obsolete, and delocalizing to countries with lower labor costs is only a step before factories become fully automated (and some companies are reshoring because robots are becoming cheaper than outshore workers). The workers here that are left with no job and no marketable skills should be manifesting for an UMI instead of asking to politics & companies to keep the factories here.

Longwelwind··on Electron 1.0 is here
Try to work with Javascript's arrays, it's a nightmare.

Fun fact:

  let list = new Array(5);
  list.forEach(() => { console.log("foo"); })
Will display nothing, if you want to properly initialize an array with a defined length, you have to do:

  let list = Array.apply(null, Array(5)).map(function () {})
I make web games in Typescript, and I get all sorts of problems like this everytime I have to work with 2D arrays, problems that I don't get when I do games in C# with Unity. Unity's modified Javascript actually implements better arrays and recommends not using Javascript's native arrays: http://docs.unity3d.com/ScriptReference/Array.html
Longwelwind··on Electron 1.0 is here
I find it more comfortable to make a GUI using HTML/CSS, but I wish I could use a more modern and more reliable language than Javascript.

Is there an equivalent to this but with Python or C# ?

Longwelwind··on Curl | sh
>curl -L https://bit.ly/janus-bootstrap | bash

I don't know for "curl | bash", but using an URL shortener there doesn't seem like a good idea.

← PreviousPage 3 of 3