HNHacker News
TopNewBestAskShowJobs

mambodog

4,836 karma · joined February 6, 2010

submissionscomments
mambodog··on Making SetInterval Declarative with React Hooks
Traits are okay: React 'Mixins' which I mentioned in my parent post are basically traits but at the framework level, which allows them to be smart about composing/merging the use of framework functionality normally accessed by overriding superclass methods (eg. componentDidUpdate). Traits still have the composability issues I mentioned for React Mixins: how do you avoid collisions between the namespaces of different traits while still allowing some to compose others?
mambodog··on Making SetInterval Declarative with React Hooks
How do you compose two base classes into a subclass? That's basically what hooks allows. You can use two different, unrelated custom hooks in one component, and a different combination in another component, without having to bundle them into base classes.
mambodog··on Making SetInterval Declarative with React Hooks
Hooks address a very specific problem with classes: composability.

You can use the various builtin hooks to do stuff that (in class-based React) previously required implementing methods (eg. componentDidUpdate). Using those methods works fine until you want to split out and reuse part of those methods in other components.

You can certainly try class composition: creating little classes that you call in each of the relevant lifecycle methods. However this adds a lot of boilerplate to components which use the composed objects (as is common with class composition). It's also awkward to share the setState API with these composed classes.

The Custom Hooks approach[1] with React Hooks just makes it really easy to use state and lifecycle functionality when extracting common behaviour to can be shared between multiple components.

React has tried to address this composition issue several times in the past, and I think hooks are the nicest yet:

React's old 'Mixins' feature got a lot of the way there, but still didn't compose perfectly. For example, you had to avoid method and state key name collisions between mixins.

Creating a 'Higher Order Component' is another approach, which is less verbose than class composition, but makes your component tree deeper, and can also be annoying to statically type.

The community also came up with 'Render Props' to address much the same issue.

And of course, you can always just continue to use classes if you aren't experiencing any of these pain points.

Hooks just compose quite nicely in cases where none of these other approaches do.

[1]: https://reactjs.org/docs/hooks-custom.html

mambodog··on How Does setState Know What to Do?
I would recommend just following the official React tutorial: https://reactjs.org/tutorial/tutorial.html

There are many other tutorials on the web but the official one has had a lot of work put in to making it seamless and letting you get a feel for what it's like to work with React without throwing too many tangential ideas at you.

mambodog··on MacOS System 6, Version 6.0.8: run in browser
For anyone who is interested in some technical background, I wrote about porting this emulator to browser a little while ago: https://jamesfriend.com.au/porting-pce-emulator-browser
mambodog··on Show HN: Node.js node_modules file pruning
The Yarn autoclean command also does something like this: https://yarnpkg.com/lang/en/docs/cli/autoclean/
mambodog··on Tech companies declare war on hate speech and conservatives are worried
Hold on. I'm not a fan of Communism, but there's a pretty clear difference. The Soviet Union was a particular implementation of Communism which chose killing. Killing is not an inherent requirement to the ideology. Contemporary proponents of Communism or Socialism usually aren't claiming that the Soviet Union's implementation was good. In Neo-Nazism the ideology itself has the elimination of other races as its goal. The ideology itself is violence. Talk about false equivalence.
mambodog··on Facebook with Adblocker makes 2000+ requests
when you haphazardly cut out chunks of an application it doesn't work correctly? colour me surprised
mambodog··on Decaffeinating a Large CoffeeScript Codebase Without Losing Sleep
Actually if you still really want JSX in CoffeeScript, it's now built in: https://github.com/jashkenas/coffeescript/pull/4551
mambodog··on Tania – PHP-based free and open source farming management system
There's a whole bunch of products in the 'farm management system' category. YC's entry is called Farmlogs. I previously worked for another such company called Agworld.

https://www.google.com/search?q=farm+management+system

mambodog··on A ReasonReact Tutorial
For people who want to look at some Reason code, here are some more projects:

https://github.com/jsdf/reason-react-hacker-news (rather unimaginatively, a hacker news app)

https://github.com/jsdf/lisp.re (native, the start of a lisp in Reason)

mambodog··on React, Relay and GraphQL: Under the Hood of the Times Website Redesign
Fair enough. What I'm trying to get at is that you need to pay attention to the cost of the real world queries which are actually being executed against your API, and then optimize. I'm not sure that SQL is a magic bullet there either (you can still request too much data at once, for example).

In practice this probably means adding some logging of how long requests take and graphing it (say, 95th percentile request time) from time to time to spot pathological queries. Even better if you can automate it. I think this is stuff that everyone should be doing (after a certain stage), regardless of whether you are using GraphQL or a bespoke JSON API.

mambodog··on React, Relay and GraphQL: Under the Hood of the Times Website Redesign
If you have low latency queries (eg. because most things hit cache rather than db) sequential queries aren't as much of a problem. Being able to join everything into one query, on the other hand, is a luxury which can be hard to maintain at scale.

In the 'join in SQL' case you could identify particular cases which are doing sequential queries and implement a different loader which just does one. It's not automatic but perhaps in most cases it's not necessary to do this step anyway. In the worst case you're back to doing as much work as you would for a bespoke API endpoint, but that's not the typical case. How much of a problem this ends up being in practice very much depends on the type of app you're building and how you intend to scale it.

mambodog··on A First Reason React App for JavaScript Developers
I don't think Reason is like Elm in this way. Whereas Elm requires you to wholly buy in to the Elm world, Reason can easily be brought into a large existing codebase.

Large chunks of messenger.com are written in Reason. I'm pretty sure that qualifies as a 'web app'.

mambodog··on A First Reason React App for JavaScript Developers
At this stage, the only thing you need to do to get Reason to 'work' is to use Create Reason React App (when targeting the browser).

The language/compiler itself is installed as an npm package(!). The only other things to install are the CLI tools (again, just an 'npm install' away) and optionally a plugin for your editor.

mambodog··on A First Reason React App for JavaScript Developers
If your question is about why one would use Reason, Reason is an interesting alternative to Javascript for building web front ends (though it also can compile to very fast native code for backend/systems use too).

Some things I feel are an improvement over Javascript + Flow or Typescript are:

- immutable data structures built into the language (and more conventionally used)

- real pattern matching on types, 'variant' types (like enums in Rust)

- better dead code elimination (helps to keep browser payload size down)

- you can use expressions everywhere (allowing more flexible code style than Javascript)

- currying/partial evaluation

- under the hood it's really just OCaml, which has benefitted from many years of development and improvement

mambodog··on An inside look at Quantum DOM Scheduling
Are you talking about async DOM APIs? Because I'm pretty sure framework authors have been explicitly asking for that.
mambodog··on Pushing Polygons on the Mega Drive
The use of vector graphics instead of 3d rendering or bitmap video seems reminiscent of the techniques which allowed Another World to achieve the fidelity it did on the consoles of that era: https://www.youtube.com/watch?v=X7GVubkh4TE

Tech overview: http://fabiensanglard.net/anotherWorld_code_review/

mambodog··on When Bash scripts bite
I highly recommend ShellCheck[0] if you're writing any bash. With the warnings and stylistic advice it provides, I feel like I can actually be confident that my scripts are doing what I think they're doing.

[0]: https://github.com/koalaman/shellcheck

mambodog··on Build Yourself a Redux
Sounds like you're confusing 'simple' with 'easy'. Rich Hickey does a good job of contrasting the two in Simple Made Easy[0].

The essential part of Redux is only 44 lines of simple code [1]. You can understand everything that it is doing. That is simple. It doesn't mean that it's going to be a great experience to work with (you might want to add some abstraction on top to make it also 'easy'), but it is definitely simple.

[0]: https://www.infoq.com/presentations/Simple-Made-Easy

[1]: https://gist.github.com/gaearon/ffd88b0e4f00b22c3159#file-sl...

mambodog··on How I learned React Native in a weekend and shipped an app
You probably don't need Redux if it's just simple persistence of data.

The simplest option is just to read and write a blob of JSON using the AsyncStorage API: https://facebook.github.io/react-native/docs/asyncstorage.ht...

Another option you could try is Realm, which is commercial but has a free tier (even for commercial apps) and has a pretty simple API: https://news.realm.io/news/introducing-realm-react-native/

Another is the SQLite module which comes with Expo:

Docs: https://docs.expo.io/versions/v16.0.0/sdk/sqlite.html Example: https://github.com/expo/sqlite-example/blob/master/main.js

mambodog··on When Does a Project Need React?
What about 'view state' such as which tokens have been typed into a typeahead/tagging style input? Or the expansion state of levels of a tree view? The active tab of a tabbed UI?
mambodog··on When Does a Project Need React?
I think manual DOM manipulation and lack of canonical state representation are both sources of spaghetti code; which one hurts more depends on the type of app you're building.

Having the DOM as your canonical representation of state is only suitable for apps with limited state IMO, because your state effectively has to be turned into text (CSS class names and element attributes) whenever it is mutated, which becomes a liability as the complexity of your app state grows.

mambodog··on A response to “An experienced JavaScript dev’s account of learning React”
Sorry, I should have said 'the question' rather than 'your question'. The original article attempted to pull in the author's issues with a bunch of React-adjacent technologies to what was purportedly a criticism of React, and I just wanted to make the point that this is needlessly muddying the waters.
mambodog··on A response to “An experienced JavaScript dev’s account of learning React”
This part of the original article was referring to React Native. React != React Native, they are two separate projects.

I realise that doesn't answer your question (which seems to be 'please justify React Native having a lot of open Github issues and being seemingly less stable than React') but it seems a bit misleading to conflate the two projects, and to expect the same amount of stability from each. React is a UI library. React Native comprises of a UI library, a JS <-> native binding system with wrappers for native APIs, a build system, and an implementation of CSS-like layout for native views. They are not really comparable.

mambodog··on The U.S. wind industry now employs more than 100K people
I think you mean 'on average, nuclear is safer than rooftop solar'. How about nuclear vs. large scale solar? Large scale solar + wind? These are more realistic equivalents to nuclear.
mambodog··on An experienced Javascript developer’s account of learning React
This post is misleading throughout.

The article shows snippets from the Redux and React Router docs, implying they are realistic examples of the way that typical React code should look, however, they are clearly snippets which are trying to show the entirety of an API on one screen. If your code is just a bunch of snippets copy-pasted from docs without much thought given to the structure of your code, your choice of UI library isn't the problem.

On React Router, React Router is not React. You don't need to use React Router. There are plenty of stable pure JS routing libraries, which don't release new versions often (or ever, because they are 'done'). Nothing about React requires you to use a React-related routing library.

The author found Redux and MobX too complex for their use case. However, Redux and MobX are not required to use React (there seems to be a theme here), and probably not useful if you don't have a big single page app with a lot of client side state. Implying they are intrinsic aspects of using React is wrong.

The bits at the end:

you will need to import in your scripts react-dom and react without never using the last one instance for some wild reason known only by the React team

The react and react-dom packages are being split so react-native doesn't have to pull in dependencies which are only used on the web. Not that different to Rails splitting up into a bunch of gems.

you can render functional components just by using js functions but you will need to wrap all your markup always in a wrapper tag to properly allow the Virtual DOM creation

This was an architectural limitation which is going away in the next major version.

its apparent simplicity is hidden behind a whole toolchain you need to configure before you can even writing 1 line of code

Why complain about this but refuse to use create-react-app? It literally solves this problem.

I started my app with React 15.5.0 knowing that my code is deprecate before even starting because facebook has just announced that for the next major release they are planning a complete rewrite of the framework and this means that they will likely nuke the current source because it can be no longer maintained.

This is FUD. The team has said that the next version of React will have some small breaking changes, but the API will remain almost completely the same. Not sure what they mean by 'nuke the current source' though.

mambodog··on The U.S. wind industry now employs more than 100K people
Humans have shown time and time again we cannot be trusted to consistently do things right, so the likely outcomes of some realistic percentage of 'terrible planning', as you put it, should be part of any comparison of power generation techniques.

The analogy you make to solar ignores that the failure modes of nuclear are much worse than solar.

mambodog··on Facebook Announces React Fiber, a Rewrite of Its React Framework
This app was written by a manager, don't read into it too much ;)
mambodog··on Early Macintosh Emulation Comes to the Archive
PCE has very simple code, and unlike Basilisk II, doesn't make use of threads (which Emscripten didn't support at the time). Basilisk II also uses a SIGSEGV handler to catch invalid memory accesses, this would have to be coded around. I'd still like to port Basilisk II, which is feasible now due to new browser APIs, but it's a big project.

The Macintosh ROM is up to the website (e.g. archive.org) to provide, along with the disk images.

← PreviousPage 2 of 23Next →