avatarGabriel Shanahan

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4405

Abstract

er based on the prompt “A Dan Flavin art of a rabbit”.</figcaption></figure><p id="2b9b">It’s a beauty. Simple, poetic, surprising. The reference to Dan Flavin creates an atmospheric, illuminated render of the rabbit. I could see this as a piece in my own space.</p><p id="16cf" type="7">“An Isamu Noguchi art of a rabbit”</p><figure id="8d22"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*gj4fxhoA7HyROuRpYyb8Ig.png"><figcaption>A DALL-E render based on the prompt “An Isamu Noguchi art of a rabbit”.</figcaption></figure><p id="113c">Stunning. There is a bit of surrealism in the form itself, but it’s an impressive concept of a rabbit.</p><p id="03ce" type="7">“A Barbara Hepworth sculpture of a rabbit”</p><figure id="4eee"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*7LOC2oigQDzizr7kBf2stg.png"><figcaption>A DALL-E render based on the prompt “A Barbara Hepworth sculpture of a rabbit”.</figcaption></figure><p id="7855">This render looks right out of the imaginary sculpture park itself. The texture is amazingly realistic, the composition is dynamic. In its poise, the rabbit displays a big personality.</p><h1 id="830a">Defining the three-prong prompt: A sculptural reference, persona, and an action</h1><p id="5b77">Now that we’ve explored a basic static DALL-E render of a sculptural reference, we can expand the prompt with a third contextual element, <b>action</b>.</p><p id="56be">We’ll ask for the rabbit to be active, jumping, or leaping.</p><figure id="3b09"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*lYLI6loWGLuEmEit8uZNKw.png"><figcaption>Adding ‘action’ to the initial prompt. This defines the 3-prong approach for the prompt.</figcaption></figure><p id="2f0c">Defining an action for our persona will add fluidity and spatial aspects. We can describe the action as leaping, or jumping through the air.</p><p id="360c">The prompts for DALL-E are thus:</p><p id="e870" type="7">“A Dan Flavin art of a rabbit leaping through the air”</p><figure id="a91c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*OhgL44MaPkgu2NcnBBcPwA.png"><figcaption>A DALL-E render based on the 3-prong prompt “A Dan Flavin art of a rabbit leaping through the air”.</figcaption></figure><p id="1c1b">DALL-E rendered this beautifully based on the 3-prong input. The image has a cinematic, ethereal quality. While we’re not sure where this narrative is going, it can be the take-off point for the rabbit hero story.</p><p id="ac7b" type="7">“An Isamu Noguchi sculpture of a rabbit jumping through mid air”</p><figure id="5b4e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*-tfcnwiVkpOpni9ziPb53Q.png"><figcaption>A DALL-E render based on the 3-prong prompt “An Isamu Noguchi sculpture of a rabbit jumping through mid air”.</figcaption></figure><p id="9b64">In this DALL-E image, the hero, the rabbit is taking on a playful personality, jumping into the air, escaping the picture, leaping into his freedom. Action here defines the hero as having energy and aspirations.</p><p id="6506" type="7">“A Barbara Hepworth sculpture of a rabbit jumping”</p><figure id="60fc"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*tn92Rom8N8RRMEy5-MTVvg.png"><figcaption>A DALL-E render based on the 3-prong prompt “A Barbara Hepworth sculpture of a rabbit jumping”.</figcaption></figure><p id="c4a3">This DALL-E rabbit seems to be dancing on his concrete cube, excited to be in this park-like environment. The action here adds delightfulness and subtlety.</p><h1 id="0612">Defining the four-prong prompt: The sculptural reference, persona, action, and environment</h1><p id="600e">We can expand a 3-prong set-up to include any other attribute. We can set the stage by defining the surroundings, colors, expression, background, textures, and so many other aspects.</p><figure id="44e0"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*_LiLU-WRYZnBBdfaLNyXCQ.png"><figcaption>An illustrative outline of a 4-prong approach to crafting the prompt. This includes the sculptural style reference, the hero (rabbit), the action, and the environment.</figcaption></figure><p id="b24a">For this exploration, we define the environment on the Barbara-Hepworth-inspired dancing rabbit.</p><p id="5bd8" type="7">“A Barbara Hepworth sculpture of a rabbit diving into a big swimming pool”</p><figure id="cc8

Options

f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*VM3eVfQ3YmXeriXWTUAQBA.png"><figcaption>A DALL-E render based on the 4-prong prompt “A Barbara Hepworth sculpture of a rabbit diving into a big swimming pool”.</figcaption></figure><p id="0744">It’s a nice rendering, although it took a few rounds to get a render of the rabbit’s entire body. The form of the sculpture is lovely, smooth, and artistic. I could see this sculpture in someone’s swimming pool.</p><p id="3c60">This can become an idea for a prototype. Or it can be a visual cue for a story that yet has to be written.</p><p id="58a0">Expanding on the prompts can add interesting dimensions, although it will take several tries before DALL-E can loosely match one’s expectation, even on a rudimentary level.</p><h1 id="f09d">Learnings and takeaways</h1><p id="e758">DALL-E renders take time (and money). They need a meaningful prompts to make a render valuable to the designer.</p><p id="ea35">Crafting a prompt takes a conceptual input. We need to define our expectations of a DALL-E render. (Randomness is fine, but unsurprisingly, the outcome is unpredictable).</p><p id="4faf">It is important to know the artistic style references well. Read up about artists’ and their work and look images of their oeuvre. Delve into their universe that took them decades to create.</p><p id="6c89">Study art history, visit museums, attend art lectures, research art movements. It will come in handy when you need to write design inputs.</p><p id="47f6">Keep being amazed by what you see around you and make a note of it.</p><p id="2ce2">Experiment with the prompt, but don’t ask for the impossible. Remember, DALL-E pulls from open source databases. DALL-E doesn’t have the human ability to bend its mind around corners.</p><p id="5f04">Remain humble and always remember, DALL-E does not replace the human imagination and creative mind. DALL-E is a tool. We can use it to explore.</p><p id="bd7b">Above all, enjoy the journey into AI.</p><p id="87ca">And then, take a break from it all.</p><p id="734f"><b>Interested in learning more about UX design, AI, design tools & trends, and art? Join Medium with <a href="https://evaschicker2012.medium.com/membership">this link</a>, and support my future writing. Thank you! </b>✍️🧡</p><p id="7ff8"><i>All images created with DALL-E ©Eva Schicker 2023.</i></p><p id="be5c">Read more about AI and design:</p><div id="f8f5" class="link-block"> <a href="https://evaschicker.medium.com/applying-abstract-art-references-to-dall-e-as-stylistic-concepts-55a000660f8c"> <div> <div> <h2>Applying abstract art references to DALL-E as stylistic concepts</h2> <div><h3>5 explorations on how DALL-E’s AI is interpreting modernist art styles</h3></div> <div><p>evaschicker.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*FJxhtMEaieIBKV-Tqsu18w.jpeg)"></div> </div> </div> </a> </div><div id="144e" class="link-block"> <a href="https://evaschicker.medium.com/how-to-explore-the-golden-ratio-in-design-and-typography-b124331ba378"> <div> <div> <h2>How to explore the golden ratio in design and typography</h2> <div><h3>The secret lies in 1.61803398875</h3></div> <div><p>evaschicker.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*6VIjPYDeIFm-JvSKNYg50g.jpeg)"></div> </div> </div> </a> </div><div id="770e" class="link-block"> <a href="https://evaschicker.medium.com/creating-steam-in-css-d8641ba7525c"> <div> <div> <h2>Creating steam in CSS</h2> <div><h3>Think hot, delightful, freshly brewed coffee</h3></div> <div><p>evaschicker.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*VuQaTsutYWfyUueWNHz2aQ.gif)"></div> </div> </div> </a> </div><p id="0bce">Thank you.</p></article></body>

Programming with Result: Motivation

Discussing all the problems with exceptions, how they’re GOTO in disguise, break basic OOP principles and what we actually use them for. A teaser of something better than exceptions.

— — — — — — — — — — — — — — —

THE CURRENT VERSION OF THIS ARTICLE IS PUBLISHED HERE.

— — — — — — — — — — — — — — —

Tags: #FUNDAMENTAL CONCEPT

This article is part of the Kotlin Primer, an opinionated guide to the Kotlin language, which is indented to help facilitate Kotlin adoption inside Java-centric organizations. It was originally written as an organizational learning resource for Etnetera a.s. and I would like to express my sincere gratitude for their support.

It is recommended to read the Introduction before moving on. Check out the Table of Contents for all articles.

Before we start, let me say that the following articles about Programming with Result are, in my view, among the most important ones in the entire set of materials — few, if any, other sections have the potential to more profoundly impact the way you design and write code. In effect, this is a continuation of the articles on strongly typed programming techniques in section on Sealed Hierarchies. If necessary, refresh your memory before reading on.

We previously demonstrated that modeling error states as types leads to safer, simpler and better maintainable code. However, in that section, we dealt mainly with “business” errors — invalid user input, for example — that are defined and happen in the business layer, as part of a business scenario. In other words, the places they occur are places that we actually wrote.

However, those are not the only errors we encounter in the wild. A large portion of errors occur outside our own code — in third party libraries such as Spring, or connectors to databases, or web servers, or even the JVM (StackOverflowError, OutOfMemoryError etc.). In those situations, we do not have the option of preventing exceptions from being thrown. A natural question to ask is: in these situations, can we apply a similar type-centric approach to modeling error states? This is the question we’ll be answering in the following articles.

The status quo

Let’s take a specific example and look at how things “normally” work. Say you are using a third party library (e.g. Spring) and have a ProductRepository, which has a method retrieveById(id: Long) that retrieves the product associated with the given id. If the id is not found, it throws an ObjectNotFoundException exception.

Now, say you’re writing a ProductService, which should have a retrieve(id: Long) method that you want to implement.

Here’s a naive solution:

You will immediately say that this is bad design — the third-party ObjectNotFoundException exception should not be part of the service layer, it should be translated to a domain-specific exception.

However, ask yourself this: is that the only exception that is can be thrown? What if the DB gets killed at the precise moment this code is executing? What if the network times out? Just browsing through Hibernate, this is the list of exceptions I found in a single method related to retrieval by id: ObjectNotFoundException, MappingException, TypeMismatchException, ClassCastException, JDBCException. If you really wanted to do things by the book, you would have to catch all of these, map them to your domain exceptions and rethrow them. Otherwise, what's the point? The whole reason you created ProductIdDoesntExist is to separate layers, right?

So, if you’re doing things by the book, here’s what you’re actually doing:

  1. you’re spending inordinate amounts of time reading other people’s code and looking for all exceptions that get thrown
  2. you’re catching all those exceptions in every single service method and translating them to your domain exceptions, which you re-throw. And you do this every time you cross layers. This is horrible for many obvious reasons, but especially from a design perspective, you’re tightly coupling your service code with the internals of the library (since the vast majority of these are runtime exceptions) and have to worry about its entire implementation, not just its public interface. This undermines some of the most fundamental pillars of OOP — encapsulation and abstraction.
  3. you’re re-catching all of those exceptions in some other part of the code, where you usually do two things: log the exception and transform it to a value that gets sent to the client. This other place is usually not obviously connected to the place the exception was thrown (such as ControllerAdvice) - in other words, you're basically using GOTO.

But let’s be real, you’re not actually going to do that. Here’s what you’re actually going to do: you’re going to ignore most of the exceptions, just catch the “typical” ones and pretend the other’s don’t exist. God forbid we start thinking about things like ThreadDeath, StackOverflowError, OutOfMemoryError and similar. The end result is that different exceptions get handled in different places, in different ways, leading to different behaviors for the user - some errors get handled nicely, such as displaying an error banner on the front end, while others just completely screw the application up.

So, in effect, you’ve either a) spent lots of time and created lots of classes, so you can create spaghetti code using GOTO in disguise, making the project more complex and less maintainable, or b) you’ve spent a little less time and created lots of classes, so you can create spaghetti code using GOTO in disguise, making the project more complex and less maintainable and also inconsistent.

Why?

Here’s the important part: why are we doing this? What’s the actual, fundamental effect these things will have?

In 99% of the cases, there will be a place (a global try/catch, ControllerAdvice, an internal Spring/Tomcat mechanism, …) that will take this exception, possibly log it, and convert it to some string value that gets sent back to the client.

In the remaining 1% of the cases, there is either an intermediate step that enriches the information by chaining the exception with a higher level exception (which again gets logged and sent to the client), or, in a tiny minority of cases, we actually do something and try to recover from the error — restart a subsystem, try connecting again, etc.

But for some reason, we feel that we cannot use normal control flow to achieve this, and instead use crazy jumps over half the code base. To make matters worse, we feel that proper design principles demand that all exceptions be translated to versions specific to that layer, even though the practical benefit of doing so is almost always 0. And since we’re only human, in practice this leads to not all exceptions being translated, only some exceptions being logged, some exceptions being logged twice, etc. There’s a lot more that could be said about why exceptions are a pile of problems just waiting to happen.

And all this for…what? To return a value, or do if (failure) { tryRecover() }. So why jump through all those hoops? Why not just do that straight away?

Read on to find out how.

Go back to Domain Specific Languages: How To Make Your Own, jump to the Table of Contents, or continue to Programming with Result: Returning a Result.

Kotlin
Java
Programming
Functional Programming
Exception Handling
Recommended from ReadMedium