Giter VIP home page Giter VIP logo

ui-effects's Introduction

Many Types Make Light Work

This is the talk which I gave at NSScotland 2014 in Edinburgh on October 26, 2014. I will be giving it at NSNorth 2015, April 10-12, 2015.

The talk is written in Deckset-flavoured Markdown.

A recording of my presentation of v1.0 of this talk at NSScotland is available.

Synopsis (for the conf)

Every programmer regularly faces the challenges of managing complexity and change. Subclassing can help us simplify, by sharing code and interfaces between related parts of our program. But when requirements change out from under our class hierarchy, unanticipated fragility can mean bugs, sweat and tears. Swift offers us a better way.

TL;DR

Subclassing is a broken idea, so factor & compose instead where possible, and when Cocoa makes you subclass, do it in a factored, composable way.

ui-effects's People

Contributors

robrix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

rredpoppy

ui-effects's Issues

Shader is tightly coupled to GLSL

This is particularly visible in the necessity of defining a main function in shaders. Functions serve no other purpose currently—there’s no mechanism to call them, for example—so it’s just another dynamically-checked error waiting to happen.

Uniforms declared & used in Shader are set in Draw

You declare & read uniforms in Shader, but set them in Draw. Since the declarations are in Shader, they aren’t visible in Draw, and so you have to use the same name essentially by coincidence.

It’d be better to bind them in Setup, use them in Shader, and set them in Draw.

Derived Foldable over ShaderF fails for Bind

It seems to work alright for Add & friends, but for Bind & MulMV it returns mempty instead of recurring.

Bind is declared as:

data ShaderF a where
  Bind :: GLSLValue a => Var (Shader a) -> ShaderF (Var (Shader a))
  …

This leads me to think that the standalone deriving machinery isn’t clever enough to connect the dots between the Var (Shader a) argument and the Var (Shader a) return. Either way, the function passed to foldMap will be Var (Shader a) -> m.

MulMV is slightly weirder:

  MulMV :: Shader (Linear.V4 a) -> Shader a -> ShaderF a

(This comes about by way of needing a matrix & vector of things. We don’t want to take a literal matrix/vector, either, we want to take shaders of those types. Type-restricted recursion is tricky!)

Shader compilation is fragile

It’s pretty easy to end up with stuff that doesn’t produce valid GLSL because of e.g. a ShaderF constructor with poorly-defined semantics.

Drawing vertices is poorly abstracted

If you want to draw the vertices for a rectangle you have to:

  1. Setup Make a list of the vertices.
  2. Setup Make an array object to hold them, & copy them in.
  3. Draw Bind the array.
  4. Draw Figure out the indices & length you need.
  5. Draw Figure out what drawing mode they were supposed to be drawn with.
  6. Draw Issue the DrawArray command.

This is bad, and it gets much worse as soon as you add a second (and third, etc) rectangle. Add some other shape, or some other geometry arrangement (e.g. different mode), and 💥

Shader in/out variable requirements aren’t enforced at compile-time

You can write fragment shaders that expect inputs not provided by the corresponding vertex shader, and vertex shaders that provide outputs which the fragment shader doesn’t expect. (The latter may not result in a runtime error; I haven’t checked.)

In either case, we already reflect the inputs/outputs by defining shaders as functions, so it should be possible to enforce that the vertex shader’s output has the same type as the fragment shader’s input.

Languages in Freer can’t be optimized

We’d like to be able to aggressively optimize languages by applying certain equalities to reduce the term tree. However, you can’t in general do optimizations (or more broadly, analyses) of languages in Freer, because Freer (being an encoding of >>=) has to perform its effects in order to traverse subterms. This is actually the mechanism by which some surface terms (e.g. stack & adjacent) operate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.