Keeping bootstrap-sass in sync with upstream changes from Bootstrap used to be an error prone and time consuming manual process. With Bootstrap 3 we have introduced a converter that automates this.
- Feb 2021
-
github.com github.com
-
-
Do not use *= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins or variables.
-
-
github.com github.com
-
It's recommended to configure this library by setting environment variables.
-
-
github.com github.com
-
STATSD_SAMPLE_RATE: (default: 1.0)
It's recommended to configure this library by setting environment variables.
The thing I don't like about configuration via environment variables is that everything is limited/reduced to the string type. You can't even use simple numeric types, let alone nice rich value objects like you could if configuration were done in the native language (Ruby).
If you try to, you get:
ENV['STATSD_SAMPLE_RATE'] = 1 config/initializers/statsd.rb:8:in `[]=': no implicit conversion of Integer into String (TypeError) -
This version makes the new client that was added in version 2.6+ the default client, and removes the legacy client. All previously deprecated functionality has been removed (since version 2.5, see below).
-
-
guides.rubyonrails.org guides.rubyonrails.org
-
Keep in mind that third party code with references to other files also processed by the asset Pipeline (images, stylesheets, etc.), will need to be rewritten to use helpers like asset_path.
-
vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks.
-
-
speakerdeck.com speakerdeck.com
-
How Sprockets works
-
-
github.com github.com
-
Some assets will be compiled as top-level assets when they are referenced from inside of another asset. For example, the asset_url erb helper will automatically link assets:
-
but if you were previously using regexp or proc values, they won't work at all with Sprockets 4, and if you try you'll get an exception raised that looks like NoMethodError: undefined method 'start_with?'
-
To correct this, you can move these files to some subdirectory of ./app/assets/stylesheets or javascripts; or you can change the manifest.js to be more like how Rails with Sprockets 3 works, linking only the specific application files as top-level targets
-
When compiling assets with Sprockets, Sprockets needs to decide which top-level targets to compile, usually application.css, application.js, and images.
-
Here's the last issue where source maps were discussed before the beta release.
-
How do you know if source maps are working correctly? Try adding a syntax error to one of your assets and use the console to debug. Does it show the correct file and source location? Or does it reference the top level application.js file?
-
Source maps eliminate the need to serve these separate files. Instead, a special source map file can be read by the browser to help it understand how to unpack your assets. It "maps" the current, modified asset to its "source" so you can view the source when debugging. This way you can serve assets in development in the exact same way as in production.
-
Source maps are a major new feature.
-
Your Rails app Gemfile may have a line requiring sass-rails 5.0: gem 'sass-rails', '~> 5.0' # or gem 'sass-rails', '~> 5' These will prevent upgrade to sprockets 4, if you'd like to upgrade to sprockets 4 change to: gem 'sass-rails', '>= 5'
-
Sprockets 3 was a compatibility release to bridge Sprockets 4, and many deprecated things have been removed in version 4.
Tags
- link to what you are referring to
- external assets: one larger file vs. multiple smaller files (HTTP requests)
- new feature
- bundlers: top-level targets
- test plan / how to test (software development)
- dependencies: locking to specific version
- prefer simpler option
- allowing sufficient time for discussion/feedback/debate before a final decision is made
- removing legacy/deprecated things
- Sprockets: manifest.js
- workaround
- source maps
- mapping
- simplicity by design
- sprockets
- automatic
- Gemfile: version constraints
- how to check/verify/test whether something is working
- have discussion/feedback/debate in public (transparency)
- compatibility
Annotators
URL
-
-
www.schneems.com www.schneems.com
-
-
That’s it. If you have a previous “precompile” array, in your app config, it will continue to work. For continuity sake I recommend moving over those declarations to your manifest.js file so that it will be consistent.
-
programmers can try to be aware of their configuration systems and the cognitive overhead they impose on people.
-
As we know, naming is hard.
-
Another thing I don’t like is the name of the config file manifest.js. Internally Sprockets has the concept of a manifest already Sprockets::Manifest, but the two aren’t directly coupled. We also already have a “manifest” JSON file that gets generated in public/assets/ and has manifest in the name .Sprockets-manifest-140998229eec5a9a5802b31d0ef6ed25.json. I know one is a JS file and one is a JSON file, but it’s a bit confusing to talk about.
When I first heard of app/assets/config/manifest.js, I was a bit confused too, and assumed/wondered if it was related to the manifest it generates under
public. -
The name makes me think of “The Legend of Zelda”. I imagine the original Sprockets author saying “It’s dangerous to go alone” and then handing me a javascript file.
-
The link name is not very helpful, it doesn’t explain what it does very well.
-
Instead of having this confusing maze of lambdas, regexes, and strings, we could, in theory, introduce a single entry point of configuration for Sprockets to use, and in that file declare all assets we wanted to compile. Well, that’s exactly what the manifest.js file is.
-
I guess in short you could say that I don’t like this interface very much.
-
Another big issue is that the config wasn’t really expressive enough. From the beginning Rails needed a way to say “only compile application.css and application.js, but compile ALL images” by default. With our previous interface, we’re limited to only strings.
-
That’s pretty gnarly. While the name of the constant LOOSE_APP_ASSETS gives me some idea of what it does, it still takes a second to wrap your mind around. If you were trying to figure out what assets are being precompiled and you did a puts config.assets.precompile that lambda object would be utterly baffling.
-
Another thing I don’t like: our asset behavior is decoupled from the assets. If you’re mucking around in your app/assets folder, then you have to first know that such a config exists, and then hunt it down in a totally different config folder. It would be nice if, while we’re working in asset land, we didn’t have to mentally jump around.
-
For example, what if your site has a customer interface and an “admin” interface? If the two have totally different designs and features, then it might be considerable overhead to ship the entirety of the admin interface to every customer on the regular site.
-
Before we get into what the manifest.js does, let’s look at what it is replacing.
-
When Sprockets was introduced, one of the opinions that it held strongly, is that assets such as CSS and JS should be bundled together and served in one file.
-
The alternative was to have multiple scripts or stylesheet links on one page, which would trigger multiple HTTP requests. Multiple requests mean multiple connection handshakes for each link “hey, I want some data”, “okay, I have the data”, “alright I heard that you have the data, give it to me” (SYN, ACK, SYNACK). Even once the connection is created there is a feature of TCP called TCP slow start that will throttle the speed of the data being sent at the beginning of a request to a slower speed than the end of the request. All of this means transferring one large request is faster than transferring the same data split up into several smaller requests.
-
One way to alleviate this configuration fatigue is by making configuration consistent and composable. That’s what Sprocket’s new “manifest.js” seeks to do.
-
Have you ever felt like a framework was getting in the way instead of helping you go faster? Maybe you’re stuck on some simple task that would be easy to do manually, but your framework is making you jump through configuration hoops. I end up getting lost in a sea of documentation (or no documentation), and the search for that one magical config key takes just a tad bit too long. It’s a productivity sink, and worse than the time delay it adds to my frustration throughout the day.
-
When I hit ETOOMUCHFRUSTRATION, then I’m definitely fighting the framework.
Tags
- hard to follow/read/understand
- what is the alternative?
- external assets: one larger file vs. multiple smaller files (HTTP requests)
- switching/migrating to something different
- fast load times (web pages)
- newer/better ways of doing things
- naming things is hard
- configuration
- overhead
- strong opinions
- fast startup times
- self-documenting
- gamer humor
- Sprockets: manifest.js
- intention-revealing
- discoverability: not easily discoverable
- not:
- composability
- what a mess
- not expressive enough
- bad combination/mixture/hybrid/frankenstein
- self-explanatory
- wasteful/inefficient use of resources
- general solution
- use meaningful names (programming)
- hard to understand
- cognitive load
- compatibility
- inconsistent
- co-location: not co-located
- network performance
- library/framework getting in the way more than helping you
- code organization: co-location
- programmer humor
- poor interface
- TCP
- the specific context is important
- sprockets
- design goals
- confusing
- I agree
- naming
- illustrating problem before showing solution
- messy
- consistent
Annotators
URL
-
-
www.lambdatest.com www.lambdatest.com
-
every human has a defined cognitive load that the memory can process. Making anyone process more information than defined will result in cognitive overloading.
-
-
en.wikipedia.org en.wikipedia.org
Tags
Annotators
URL
-
-
travis-ci.org travis-ci.org
-
Please be aware travis-ci.org will be shutting down in several weeks, with all accounts migrating to travis-ci.com.
-
Testing your open source projects will always be free! Seriously. Always. We like to think of it as our way of giving back to a community that connects so many people.
-
-
www.schneems.com www.schneems.com
-
TravisCI.org is dead.
-
-
stackoverflow.com stackoverflow.com
-
trailblazer.to trailblazer.to
-
So, whenever you hear the medieval argument “Trailblazer is just a nasty DSL!”, forgive your opponent, you now know better. The entire framework is based on small, clean Ruby structures that can be executed programmatically.
-
The entire framework is based on small, clean Ruby structures that can be executed programmatically.
-
-
trailblazer.to trailblazer.toTrailblazer14
-
Yes, we could and should use Reform or Dry-validation here.
-
a task in an activity can be any callable Ruby object
-
-
Each step receives the return value of its predecessor. The return value decides about what next step is called.
-
In order to invoke, or run
-
the ability to “error out” when something goes wrong
-
Six lines of code create an executable object that, when invoked, will run your code in the order as visible in our diagram, plus the ability to “error out” when something goes wrong.
-
While you could program this little piece of logic and flow yourself using a bunch of Ruby methods along with a considerable amount of ifs and elses, and maybe elsif, if you’re feeling fancy, a Trailblazer activity provides you a simple API for creating such flow without having to write and maintain any control code. It is an abstraction.
-
keeps a semantic
-
A task is often called step.
-
Your actual logic happens in tasks, the labeled boxes. A task may be any callable Ruby object, an instance method or even another activity.
-
Every path or flow stops in a terminus event. Those are the filled circles. Often, we call them end event, too!
-
The “error path” or “failure track” is the lower path going the the failure terminus.
-
The “happy path” or “success track” is the straight path from start to the terminus named success.
Tags
- different names for the same/identical thing (synonyms)
- what does this actually mean?
- railway-oriented programming
- error/exception handling
- happy path / success track
- happy path
- control flow
- good abstraction
- reduce/minimize/simplify/remove control flow code
- ruby: callable object
- typo
- Trailblazer
- tutorial
- terminology
- powerful
- too many ifs: bad
- example
- terminus/termini
- error path / failure track
- interchangeable
- abstractions
- good tutorial
- example: in order to keep example concise/focused, may not implement all best practices (illustrates one thing only)
- good explanation
- polymorphism
- programming: invoke/run/call
Annotators
URL
-
-
trailblazer.to trailblazer.toTrailblazer10
-
-
allowing you to limit what invoked tasks or nested activies “see” and what they propagate to the caller context.
-
Please note that the actual task doesn’t have to be a proc! Use a class, constant, object, as long as it exposes a #call method it will flow.
-
You may use keyword arguments in your filters for type safety and better readable code.
-
In both filters, you’re able to rename and coerce variables. This gives you a bit more control than the simpler DSL.
-
Trailblazer will automatically create a new Context object around your custom input hash. You can write to that without interferring with the original context.
-
a method that doesn’t have access to variables outside its scope
-
As usual, you may provide your own code for dynamic filtering or renaming.
-
Please note that I/O works for both “simple” tasks as well as nested activities.
-
An array value such as [:params] passed to :input will result in the configured task only “seeing” the provided list of variables. All other values are not available, mimicking a whitelist.
Tags
- trailblazer-activity
- type safety
- information hiding
- immutable data
- flexibility
- interchangeable
- annotation meta: may need new tag
- scope (programming)
- applies/works in all cases/subcases (polymorphism) (no arbitrary limitation)
- ruby: keyword arguments
- readability
- ruby: callable object
- having enough control over something
- DSL
- polymorphism
- allowlist
Annotators
URL
-
-
www.theregister.com www.theregister.com
-
-
Redmond suggests nuking 'profanity, geopolitical, diversity' terms from browser source
-
Allowlist, not whitelist. Blocklist, not blacklist. Goodbye, wtf. Microsoft scans Chromium code, lops off offensive words
-
a proposal to cleanse the open-source code of "potentially offensive terms."
-
a suggestion by Microsoft to “cleanup of potentially offensive terms in codebase” aims to rid the software blueprints of language such as whitelist (change to allowlist), blacklist (change to blocklist), “offensive terms using ‘wtf’ as protocol messages,” and other infelicities.
-
In May, Microsoft announced AI features in Word that, among other features, will emit “advice on more concise and inclusive language such as ‘police officer’ instead of ‘policeman.’"
-
-
github.com github.com
-
-
Good intentions, but I doubt there's any relation of the origin of the terms blacklist/whitelist to race. There are many idioms and phrases in the English language that make use of colours without any racial backstories. I haven't met any black person (myself included) who was ever offended by the use of "blacklist".
-
Regardless of origin, allow/deny are simply clearer terms that does not require tracing the history of black/white as representations of that meaning. We can simply use the meaning directly.
-
Frankly, a good number find it patronising to make this kind of change.
-
-
en.wikipedia.org en.wikipedia.org
-
in functional programming, the terms "conditional expression" or "conditional construct" are preferred, because these terms all have distinct meanings
-
-
-
en.wikipedia.org en.wikipedia.org
-
The forms of the final keyword vary:
-
found that using only the Pascal-provided control structures, the correct solution was given by only 20% of the subjects, while no subject wrote incorrect code for this problem if allowed to write a return from the middle of a loop.
-
What Böhm and Jacopini's article showed was that all programs could be goto-free.
-
That such minimalism is possible does not mean that it is necessarily desirable
-
computers theoretically need only one machine instruction (subtract one number from another and branch if the result is negative)
-
-
sobolevn.me sobolevn.me
-
Literally, everything in this example can go wrong. Here’s an incomplete list of all possible errors that might occur: Your network might be down, so request won’t happen at all The server might be down The server might be too busy and you will face a timeout The server might require an authentication API endpoint might not exist The user might not exist You might not have enough permissions to view it The server might fail with an internal error while processing your request The server might return an invalid or corrupted response The server might return invalid json, so the parsing will fail And the list goes on and on! There are so maybe potential problems with these three lines of code, that it is easier to say that it only accidentally works. And normally it fails with the exception.
-
Return None. That’s evil too! You either will end up with if something is not None: on almost every line and global pollution of your logic by type-checking conditionals, or will suffer from TypeError every day. Not a pleasant choice.
-
Let’s start with the same number dividing example, which returns 0 when the error happens. Maybe instead we can indicate that the result was not successful without any explicit numerical value?
-
And we can specify types of wrapped values in a function return annotation, for example Result[float, ZeroDivisionError] returns either Success[float] or Failure[ZeroDivisionError].
-
Now you can easily spot them! The rule is: if you see a Result it means that this function can throw an exception. And you even know its type in advance.
-
we also wrap them in Failure to solve the second problem: spotting potential exceptions is hard
-
exceptions are not exceptional, they represent expectable problems
-
You can use container values, that wraps actual success or error value into a thin wrapper with utility methods to work with this value. That’s exactly why we have created @dry-python/returns project. So you can make your functions return something meaningful, typed, and safe.
-
Write special-case classes. For example, you will have User base class with multiple error-subclasses like UserNotFound(User) and MissingUser(User). It might be used for some specific situations, like AnonymousUser in django, but it is not possible to wrap all your possible errors in special-case classes. It will require too much work from a developer. And over-complicate your domain model.
-
Exceptions are not exceptional
-
Exceptions are just like notorious goto statements that torn the fabric of our programs.
-
Not all cases can be covered and easily restored. And sometimes when we will reuse this function for different use-cases we will find out that it requires different restore logic.
-
But why do we return 0? Why not 1? Why not None? And while None in most cases is as bad (or even worse) than the exceptions, turns out we should heavily rely on business logic and use-cases of this function.
-
And checked exceptions won’t be supported in the nearest future.
-
Almost everything in python can fail with different types of exceptions: division, function calls, int, str, generators, iterables in for loops, attribute access, key access, even raise something() itself may fail. I am not even covering IO operations here. And checked exceptions won’t be supported in the nearest future.
-
You still need to have a solid experience to spot these potential problems in a perfectly readable and typed code.
-
So, despite your code is type safe it is not safe to be used.
-
print will never be actually executed. Because 1 / 0 is an impossible operation and ZeroDivisionError will be raised.
-
So, the sad conclusion is: all problems must be resolved individually depending on a specific usage context. There’s no silver bullet to resolve all ZeroDivisionErrors once and for all. And again, I am not even covering complex IO flows with retry policies and expotential timeouts.
Tags
- monad: Either
- railway-oriented programming
- error/exception handling
- anticipating what could go wrong / error/exception cases
- analogy
- monad: monadic value (wrapping a value within the monad)
- surprising
- key point
- sad/unfortunate conclusion
- actually consider / think about how it _should_ (ideally) be
- type safety
- too many ifs: bad
- safety (programming)
- not:
- exceptions that are not exceptional
- seemingly contradictory
- good example
- programming: goto
- exceptions are expectable, not exceptional
- the benefit of experience
- depends on use case / application
- easy to see/notice
- why?
- special cases
- accidentally works
- checked exceptions
- rule of thumb
- can't support everything / all cases
- easy to miss / not notice (attention)
- can't think of everything
- type checking
- error/exception handling: spotting potential exceptions is hard
- Python
- difficult/hard problem
- type annotations
- the specific context is important
- type checking: type annotations (unchecked; in comments)
- need to solve specific case/problems individually (there is no general solution)
- traditional exception handling (try/catch; begin/rescue)
Annotators
URL
-
-
fsharpforfunandprofit.com fsharpforfunandprofit.com
-
(when used thoughtlessly)
-
-
-
github.com github.com
-
Or you can use Maybe container! It consists of Some and Nothing types, representing existing state and empty (instead of None) state respectively.
-
So, what can we do to check for None in our programs? You can use builtin Optional type and write a lot of if some is not None: conditions. But, having null checks here and there makes your code unreadable.
-
But now, you can do the same thing in functional style!
-
Brings functional programming to Python land
-
Provides a bunch of primitives to write declarative business logic
-
Enforces better architecture
-
Make your functions return something meaningful, typed, and safe!
Tags
- type safety
- too many ifs: bad
- example
- make it hard to get wrong/incorrect
- see content below
- primitives
- software architecture
- unreadable
- programming: return values / result objects that communicate a more precise/complete representation of the outcome
- monad/container value/type
- functional programming
- declarative
- functional programming: in non-functional languages
- business logic
- monad: Maybe
Annotators
URL
-
-
drylabs.io drylabs.io
-
Our mission is to allow people to make money via educational efforts and to dedicate the rest of their time to creating great open source products.
What does this mean exactly? "Our mission is to allow people to make money via educational efforts"
-
-
-
en.wikipedia.org en.wikipedia.org
-
Examples
-
despite initially appearing to be an appropriate and effective response to a problem, has more bad consequences than good ones
-
there are two key elements to an anti-pattern that distinguish it from a bad habit, bad practice, or bad idea
-
-
-
But so far everything brought up has just been about the relative advantages of checked exceptions, and that issue is closed. We won't do it.
-
I'm not a fan of listing exceptions functions can throw, especially here in Python, where it's easier to ask forgiveness than permission.
-
certainly I wouldn't want it to start telling me that I'm not catching these!
-
I'm not a fan of checking exceptions either
-
In my past life with Java, I've had mixed feelings about exception checking. It's saved me from some mistakes more than it's been annoying. Maybe the checking of exceptions could be controlled by some notion of "unchecked exceptions"?
Tags
- Python: the Python way
- errors/warnings that may not apply to your case and be noisy/annoying to be warned about
- easier to ask forgiveness than permission
- error/exception handling
- checked exceptions
- make bold decisions
- don't constantly revisit a decision
- programming languages: requires verbosity / extra paperwork to explicitly list types/exceptions/...
- making decisive/definite/bold decisions
- intentional/well-considered decisions
- design decision
Annotators
URL
-
-
www.python.org www.python.org
-
This PEP provides a standardized means to leverage existing tooling to package and distribute type information with minimal work and an ordering for type checkers to resolve modules and collect this information for type checking.
Tags
Annotators
URL
-
-
www.morozov.is www.morozov.is
-
include Dry::Monads::Do.for(:call)
-
Railway Oriented Programming is a way to gracefully handle errors in your application
-
This is how the same example would look like using raw monads:
-
Do notation provides an alternative to bind, which also flattens the code.
-
Better control over flow of our application: more ways to add branching
-
bind applies unwrapped Success value to the block, which should return a Result object. No-op on Failure
-
It allows us to reuse steps
-
The Result object that we pass around keeps accumulating data and becomes enormous, so we have to use **rest in our function signatures
-
The DSL has a weaker control over the program’s flow — we can’t have conditions unless we add a special step
-
-
However, you don’t need to have an extensive knowledge of monads to use ROP in your code.
-
Railway Oriented Programming comes from functional programming, so it is tightly related to the usual FP concepts like monads, composition, and many others.
-
I want to emphasize that Result is just an alternative name for the Either monad.
Tags
- monad: Either
- different names for the same/identical thing (synonyms)
- alternative to:
- railway-oriented programming
- error/exception handling
- monad
- strong (extreme/great/high/intense degree/level/concentration/amount/quality of)
- advantages/merits/pros
- almost/nearly the same/identical / very similar / not very different
- monad: unwrapping
- control flow
- origin story
- don't need to fully understand in order to use
- disadvantages/drawbacks/cons
- DSL
- conditional code
- functional programming
- dry-monads (Ruby)
- it's just _
- example
- Ruby
- not:
- monad: unwrapping: bind
- do notation
- ruby
- use case
Annotators
URL
-
-
tineye.com tineye.com
-
-
boardgamegeek.com boardgamegeek.com
-
www.kickstarter.com www.kickstarter.com
-
let's be honest, print-and-play is A LOT of work (printing, cutting, laminating, sleeving, etc) and it is not everyone's cup of tea.
-
-
boardgamegeek.com boardgamegeek.comMaquis1
-
boardgamegeek.com boardgamegeek.comDEFCON 12
-
-
The game seems perfectly balanced, what is so rare for an assymétric game
-
-
www.kickstarter.com www.kickstarter.comDEFCON 12
-
The author will offer presentation/game sessions on Tabletopia, in French and English. In addition, the game will be freely available for players on Tabletopia as soon as the written rules are available.
-
-
-
www.metacritic.com www.metacritic.com
-
This is the perfect game when you are not wanting something with stakes or stress.
Tags
Annotators
URL
-
-
www.metacritic.com www.metacritic.comWarsaw1
-
Difficult enough to prove a worthy challenge, with an over-complexity that might have benefitted from a little self-restraint.
overly complex = unnecessarily complicated
-
-
www.metacritic.com www.metacritic.com
-
It seems like such a beautiful little visual novel and while I wasn’t expecting a masterpiece of localisation based on its low price, I was expecting to be able to read it. But that just cannot be done. Developers from Japan, China, Taiwan, Indonesia, and every other emerging game development centre through Asia-Pacific, listen to me carefully: You can have the most beautiful aesthetics and a heartwarming concept for your game. If the localisation isn’t going to be good, though, do not bother with an English release, because it is going to get reviews like this one. Make “invest in proper translation” your big resolution for 2021. I do not want to play any other games like Lily in the Hollow - Resurrection ever again.
-
-
www.metacritic.com www.metacritic.com#DRIVE1
-
The cars handling can be best explained as "its like steering a drunk sailor on a boat."
Tags
Annotators
URL
-
-
www.metacritic.com www.metacritic.com
-
This tedium would be unacceptable in an action game, but Windbound is a survival game. In survival games, death is supposed to mean something. Loss of progress represents the stakes; repetition is the barrier of entry.
-
-
dry-rb.org dry-rb.org
-
One can say this code is opaque compared to the previous example but keep in mind that in real code it often happens to call methods returning Maybe values.
-
this implies direct work with nil-able values which may end up with errors.
-
To get the final value you can use value_or which is a safe way to unwrap a nil-able value.
-
In other words, once you've used Maybe you cannot hit nil with a missing method. This is remarkable because even &. doesn't save you from omitting || "No state" at the end of the computation. Basically, that's what they call "Type Safety".
-
Writing code in this style is tedious and error-prone.
-
Another solution is using the Safe Navigation Operator &. introduced in Ruby 2.3 which is a bit better because this is a language feature rather than an opinionated runtime environment pollution
-
However, some people think these solutions are hacks and the problem reveals a missing abstraction.
-
It's hard to say why people think so because you certainly don't need to know category theory for using them, just like you don't need it for, say, using functions.
-
-
The gem was inspired by the Kleisli gem.
-
Monads provide an elegant way of handling errors, exceptions and chaining functions so that the code is much more understandable and has all the error handling, without all the ifs and elses.
Tags
- understandable
- functions
- monad
- inspired by
- error/exception handling
- nullable type/value
- don't modify objects you don’t own (monkey patching)
- monad: unwrapping
- don't need to fully understand in order to use
- optional chaining/safe navigation operator
- programming languages: features
- ruby library
- dry-monads (Ruby)
- elegant solution
- monad: Maybe
- opaque
- type safety
- too many ifs: bad
- remarkable
- tedious
- category theory
- make it impossible to get wrong/incorrect
- good explanation
- chaining
- problems reveal a missing abstraction
- good point
- opinionated
- reuse existing language constructs
- error-prone
- tell, don't ask
- polluting the global scope/environment
Annotators
URL
-
-
en.wikipedia.org en.wikipedia.org
-
built using nullary type constructors
first sighting nullary 
-
-
en.wikipedia.org en.wikipedia.org
-
-
Also, in non-functional programming, a function without arguments can be meaningful and not necessarily constant (due to side effects).
-
The latter are important examples which usually also exist in "purely" functional programming languages.
How can they exist and it still be considered pure??
I guess that's not quite the same / as bad as saying something had side effects in a purely functional programming context, right?
-
Often, such functions have in fact some hidden input which might be global variables, including the whole state of the system (time, free memory, …).
-
-
en.wikipedia.org en.wikipedia.org
-
Though rarer in computer science, one can use category theory directly, which defines a monad as a functor with two additional natural transformations. So to begin, a structure requires a higher-order function (or "functional") named map to qualify as a functor:
rare in computer science using category theory directly in computer science What other areas of math can be used / are rare to use directly in computer science?
-
For historical reasons, this map is instead called fmap in Haskell.
-
can transform monadic values m a applying f to the unwrapped value a
-
In fact, the Product comonad is just the dual of the Writer monad and effectively the same as the Reader monad (both discussed below)
-
procedure to wrap values of any basic type within the monad (yielding a monadic value)
-
A combinator, typically called bind (as in binding a variable) and represented with an infix operator >>=, that unwraps a monadic variable, then inserts it into a monadic function/expression, resulting in a new monadic value:(mx >>= f) : (M T, T → M U) → M U
-
A type constructor M that builds up a monadic type M T
-
A type converter, often called unit or return, that embeds an object x in the monad:.mw-parser-output .block-indent{padding-left:3em;padding-right:0;overflow:hidden}unit(x) : T → M T
-
allows monads to simplify a wide range of problems
-
another to compose functions that output monadic values (called monadic functions)
-
Monads achieve this by providing their own data type (a particular type for each type of monad), which represents a specific form of computation
-
In functional programming, a monad is an abstraction that allows structuring programs generically
Tags
- higher-order function
- monad
- advantages/merits/pros
- defining in terms of _
- simplify
- monad: unwrapping
- dual (math)
- monad: monadic value (wrapping a value within the monad)
- due to historical reasons
- _any_
- monad: data type
- annotation meta: may need new tag
- category theory
- functor
- generic programming
- abstractions
- monad: wrapping value (nomadic value)
- representing a kind of computation (monad)
- code/program structure
- monad: monadic functions (composition)
Annotators
URL
-
-
en.wikipedia.org en.wikipedia.org
-
The exception can be avoided by using ? operator on the nullable value instead:
-
The @ ? annotation can be used to denote a nullable value.
-
-
-
en.wikipedia.org en.wikipedia.org
Tags
Annotators
URL
-
-
www.martinfowler.com www.martinfowler.com
-
It reminds us that rather than asking an object for data and acting on that data, we should instead tell an object what to do.
-
-
jrsinclair.com jrsinclair.com
-
-
It’s definitely better than littering our code with endless if-statements.
-
As you can see, we end up with a lot of boilerplate if-statements. The code is more verbose. And it’s difficult to follow the main logic.
-
In JavaScript, we have a built-in language feature for dealing with exceptions. We wrap problematic code in a try…catch statement. This lets us write the ‘happy path’ in the try section, and then deal with any exceptions in the catch section. And this is not a bad thing. It allows us to focus on the task at hand, without having to think about every possible error that might occur.
-
And they are not the only way to handle errors.
-
In this article, we’ll take a look at using the ‘Either monad’ as an alternative to try...catch.
-
The .chain() method allows us to switch over to the left track if an error occurs. Note that the switches only go one way.
-
This stuff is intoxicating once you get into it.
-
Don’t worry if you get confused at first. Everyone does. I’ve listed some other references at the end that may help. But don’t give up.
-
And a word of warning. If you haven’t come across things like monads before, they might seem really… different. Working with tools like these takes a mind shift. And that can be hard work to start with.
Tags
- monad: Either
- hard to follow/read/understand
- error/exception handling
- happy path
- railway-oriented programming
- monad
- different way of thinking about something
- good illustration (visual)
- different way of solving/implementing something
- functional programming
- elegant solution
- encouragement
- you're not alone / it happens to/is like that for everyone
- too many ifs: bad
- annotation meta: may need new tag
- replacement for:
- sad path
- verbose / noisy / too much boilerplate
- traditional exception handling (try/catch; begin/rescue)
- JavaScript
- excellent technical writing
- fun
Annotators
URL
-
-
functionalprogramming.medium.com functionalprogramming.medium.com
-
polymorphic method inside shape class, its possible to discriminate them. without if’s.
-
-