<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Corné van Straten on Medium]]></title>
        <description><![CDATA[Stories by Corné van Straten on Medium]]></description>
        <link>https://medium.com/@cornvanstraten?source=rss-7abe1add283f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CIIcGSumcLDMfnyc.</url>
            <title>Stories by Corné van Straten on Medium</title>
            <link>https://medium.com/@cornvanstraten?source=rss-7abe1add283f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 13:36:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cornvanstraten/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[geospatial and text queries in MongoDB]]></title>
            <link>https://cornvanstraten.medium.com/geospatial-and-text-queries-in-mongodb-b3747cfe0104?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3747cfe0104</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Tue, 26 Oct 2021 02:12:58 GMT</pubDate>
            <atom:updated>2022-01-18T21:07:43.224Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ty8m8Y3dzgD6P5Xc17gbYw.jpeg" /></figure><p>For the project I’m working on, I need to perform a text search on listings within a specific area. In this article, I want to <a href="https://cornevanstraten.com/learning-out-loud/">learn out loud</a> about my process of developing this feature for my project, by discussing the problems I run into and which solutions I’m considering.</p><h3>Use case</h3><p>Together with my team of <a href="https://successfuldropout.com/">successful dropouts</a>, I’m developing an open marketplace for learning in real life. The idea is that anybody that has something to teach can create a listing and be found by people close to them, so that they can learn from that person directly, in real life.</p><p>Because of this, a user needs to be able to search within a certain radius of their location, but also be able to perform a text search to find something specific he or she may want to learn, such as welding, drone flying or self-defense.</p><p>We’re building the web application using the MEVN stack, which means that we use a reactive Vue app in the frontend that consumes a NodeJS API, built on top of a Mongo database.</p><h3>Step 1: geoSearch with $geoNear</h3><p>I decided to build this feature from the ground up, starting with geoSearch: the feature that allows you to search within a certain radius from a specific geographical point.</p><p>This part is actually fairly easy with MongoDB, which is a big selling point for this open source document database; and one of my main reasons for using it.</p><p>Mongo supports several <a href="http://geojson.org/">geoJSON</a> object types, but for our use case we’re going to work with points, mostly. The coordinates are listed in an array with the longitude first and then the latitude.</p><p>Working with the $geoNear operator requires a <a href="https://docs.mongodb.com/manual/core/geospatial-indexes/">geoSpatial index</a>. Creating an index like this is very straightforward using mongoose and makes the Schema look like this:</p><pre>const geoSchema = new mongoose.Schema(<br>   { type: <br>      { type: String, default: &quot;Point&quot; }, <br>      coordinates: { <br>         type: [Number], index: &quot;2dsphere&quot; //creates the index <br>      } <br>   }<br>)</pre><p>This geoSchema can then be inserted in the mongoose Schema for the listing itself, under geometry:</p><pre>const listingSchema = new mongoose.Schema(<br>   { <br>      _id: mongoose.Schema.Types.ObjectId, <br>      title: {type: String, required: true}, <br>      description: {type: String, required: true}, <br>      price: {type: Number, required: true}, <br>      geometry: geoSchema <br>   }<br>);</pre><p>After the Schema is created, the next step is using the <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/">$geoNear</a> operator in the route as follows:</p><pre>Listing.aggregate([ <br>   { <br>     $geoNear: { <br>        near: { type: &#39;Point&#39;, coordinates: coordinates },    <br>        distanceField: &quot;dist.calculated&quot;, <br>        maxDistance: parseFloat(req.query.distance), <br>        query: { price: { $lt: pricemax} }, <br>        spherical: true <br>     } <br>   } <br>])</pre><p>This $geoNear operation will output documents in order of nearest to farthest from the specified point. It also includes the calculated distance to that specified point under the field specified under distanceField.</p><p>As you can see, the $geoNear operation also supports adding a query field to limit the results to the documents that match the query. In this case, we’re looking for listings where the price is lower than ($lt) the maximum price pricemax that the user specified.</p><p>This all works very well, and very quickly and efficiently thanks to the geoSpatial index we’re using. So far, so good.</p><h3>Step 2: full text search with $text</h3><p>Mongo also provides the opportunity to do a full text search of all the documents in a collection using the <a href="https://docs.mongodb.com/manual/reference/operator/query/text/index.html">$text</a> operator. This operation takes the specified text, parses it and performs an OR query for matches of the <em>stemmed </em>word.</p><p>This operation also requires an index on the text fields to be searched (e.g. title and description). Using mongoose, we can create such an index in the following way:</p><pre>listingSchema.index({ title: &#39;text&#39;, description: &#39;text&#39;}) //creates index</pre><p>A full text search can then be performed as follows:</p><pre>Listing.find({ $text: { $search: &quot;bake coffee cake&quot; } })</pre><p>This operation will then perform a search in the indexed fields, in this case title and description, and return all the documents that match the query.</p><p>This operation also works perfectly well, quickly and efficiently thanks to the text index we’re using. So far, so good; again.</p><p>Seeing that both operations work perfectly well, it would be easy to think that you could just aggregate both operations in a pipeline and find documents that both match the search query and the geospatial query. But you’d be wrong.</p><h3>Problem: clash of indexes</h3><p>The problem that arises if you try to combine geoSearch and textSearch like this, is that you <strong>cannot use two indexes simultaneously</strong>. Unfortunately, <a href="https://stackoverflow.com/questions/33765288/using-full-text-search-with-geospatial-index-on-mongodb">there is no way to combine $geoNear and $text</a>, because they both require an index to work.</p><h3>Why can you not use both indexes simultaneously?</h3><p>To understand why you cannot use both indexes simultaneously, you first have to understand how databases based on the document model work; and what indexes really are in such an environment.</p><h3>Document-model</h3><p>Mongo (and other similar non-relational/noSQL databases) are based on the document-model, making it fundamentally different from relational database management systems, such as mySQL and Postgres; and more similar to most real life filing systems.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FEE8ZTQxa0AM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DEE8ZTQxa0AM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FEE8ZTQxa0AM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/475abe88b479403f9be15d4ac4b59e17/href">https://medium.com/media/475abe88b479403f9be15d4ac4b59e17/href</a></iframe><p>The document model is a key design choice for Mongo as a database system; and it comes with its pros and cons.</p><h3>Pros:</h3><ul><li><strong>Simple setup:</strong> increasing speed of development</li><li><strong>Fast:</strong> certain operations are faster and more efficient, because all relevant information is stored in one place</li><li><strong>Flexible: </strong>it is easy to add features at a later stage</li><li><strong>Scalable:</strong> supports horizontal partitions (shards) out of the box</li><li><strong>Location features</strong> for geospatial queries such as <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/">$geoNear</a></li></ul><h3>Cons:</h3><ul><li><strong>Redundancy:</strong> the document model sometimes forces you to store redundant information</li><li><strong>Inefficient: </strong>document model makes certain operations slow and inefficient, for example when information that is stored redundantly in many documents needs to be updated</li></ul><p>Database systems based on the document model are definitely not always the right choice. If your use case is full of different sorts of entities that have all kinds of different relationships to each other, a relational database management system such as mySQL will probably still be the right choice.</p><p>In our use case, however, the modeling required can be simply structured in a way similar to a human filing system. And that, together with the flexibility, scalability and speed of development made Mongo the right choice for our project.</p><h3>Indexing documents</h3><p>Now that you understand how document-based databases like Mongo work, it’s time to discuss what an index really is. And it is helpful, in this regard, to think of the index in a book, especially considering the document-like nature of databases like Mongo.</p><p>Whether it be in a book or in a database, the goal of an index is to make it quicker to find something. An index in a book makes sure that you don’t have to browse through the whole book to find that specific section you’re looking for. In the same way, databases use indexes to prevent having to search through the entire database to find a small number of documents.</p><p>For our purposes, consider that you have a pretty comprehensive management book with well over a thousand pages, divided up into 101 chapters. And you’re looking for a few sections in the book about the hiring and firing process.</p><p>Luckily, the book features two sorts of indexes. In the front of the book, there is a table of contents. This is a very simple index: a document listing chapter titles and their corresponding page numbers.</p><p>In the back of the book there is also a keyword index. This is a document listing keywords and corresponding page numbers.</p><p>Now, to find the section you are looking for you could do a few things.</p><p>Firstly, you could browse through the entire book and see if you find the sections you are looking for. This is obviously the least efficient and the most time-consuming option.</p><p>Secondly, you could look through the table of contents and see if you find any chapter titles that mention something about dealing with employees; and then browse through those chapters to see if you can find what you’re looking for. This would be way more efficient.</p><p>Thirdly, you could look up the words <em>hiring</em> and <em>firing</em> in the keyword index; and look up the pages where those words are mentioned. This too, would be way more efficient than just browsing through the book.</p><p>What you would almost certainly not do, though, is first look through the table of contents to find chapters that deal with employees; then also go through the keyword index in the back of the book to find which pages mention the words <em>hiring</em> and <em>firing</em>; and then combine the data you found, by cross-referencing the page numbers with the chapters, to determine which pages you’re actually going to look at.</p><p>In other words, you would not use two indexes simultaneously, because it would be so grossly inefficient as to defeat the entire purpose of using that second index after the first one.</p><p>So, <a href="https://stackoverflow.com/questions/33765288/using-full-text-search-with-geospatial-index-on-mongodb">there is no way to combine $geoNear and $text</a>, because they both require an index to work.</p><p>But no coder would be worth his salt if he just accepted the challenges he faced and gave up. So I’m considering a few possible solutions, that I will further discuss in part 3 of this series.</p><h3>Solution 1: just don’t</h3><p>Firstly, consider whether or not you even really need this feature. Because when I was doing research online, I found out that <a href="https://cornevanstraten.com/mongodb-geosearch-1/">our use case</a> is pretty unique.</p><blockquote><em>It is very rare that an application needs to let the user perform a text search and a geospatial search at the same time. It’s usually either/or.</em></blockquote><p>Either you’re looking for something specific, close to your location, like a hotel, in which case you can use a few filters (e.g. 2 bedrooms + swimming pool) to narrow down the search; OR you’re performing an actual fuzzy text search and location is largely irrelevant. Think about it:</p><ul><li><strong>Airbnb: </strong>location + filters, no text search</li><li><strong>Amazon:</strong> text search + filters, no location</li><li><strong>Zillow: </strong>location + filters, no text search</li><li><strong>Netflix: </strong>text search + filters, no location</li><li><strong>Gym locator: </strong>location + filters, no text search</li><li><strong>Udemy: </strong>text search + filters, no location</li></ul><p>There are exceptions here, of course, but the feature is not as common as you might think. Usually, a geospatial search does not have to be combined with a full text search.</p><p>So the first solution you should consider is if you could get away with doing a location search providing filters, similar to how AirBnb does it. Chances are, you don’t even need to combine text and geospatial search and a few clever filter options will do the trick.</p><h3>Solution 2: $geoNear + regex</h3><p>Another solution is to keep using the indexed (fast) $geoNear operator, but instead of using $text, you filter the result set with a <a href="https://regexone.com/">regular expression</a> regex in the query, like so:</p><pre>Listing.aggregate([<br>    {<br>      $geoNear: {<br>        near: {<br>          type: &#39;Point&#39;,<br>          coordinates: coordinates<br>        },<br>        distanceField: &quot;dist.calculated&quot;,<br>        maxDistance: parseFloat(req.query.distance),<br>        query: {<br>            $or: [<br>                {title: regex},<br>                {description: regex}<br>              ],<br>              price: { $lt: pricemax}<br>        },<br>        spherical: true<br>      }<br>    }<br>  ])</pre><p>This works pretty well, but the downside here is that you can not use the magic of the $text search operator, such as <em>stemming</em> (baking → bake) and removal of irrelevant words (e.g. ‘the’).</p><p>You can only search for what a user literally types in; and that also means that it’s going to require extra effort to figure out how to deal with multiple words. This could turn out to be a problem, because so-called <a href="https://www.wordstream.com/long-tail-keywords">longtail searches</a> are becoming more and more common.</p><h3>Solution 3: $text + $geoWithin</h3><p>Another solution is to put the search magic of $text first, and then filter the results using the <a href="https://docs.mongodb.com/manual/reference/operator/query/geoWithin/">$geoWithin</a> operator. This works, because the $geoWithin operator does not require an index.</p><pre>Listing.find({ <br>    $text: { <br>         $search: &quot;bake coffee cake&quot; <br>     },<br>     geometry: {<br>        $geoWithin: {<br>            $centerSphere: [coordinates, distance]<br>        }<br>    }    <br> })</pre><p>Upside here is text search is going to work very well; because it will use Mongo’s full-text-search technology.</p><p>Downside is that not using an index on the geospatial search makes the query relatively slow and inefficient; because it is going to have to go through each and every document that matches the text search to see which of those are within range of the specified coordinates.</p><p>So to decide if this is the right option for you, you have to decide which part of the query will narrow down the results more, the text search or the geospatial.</p><h3>Solution 4: server-side search library</h3><p>The fourth possible solution is very similar to solution 2. You keep using the indexed (fast) $geoNear operator, but instead of using $text or a <a href="https://regexone.com/">regular expression</a> regex in the query, you use an external search library to perform a text search through the results, right on the server, before returning the results.</p><p>Because I work in NodeJS on the backend, I am looking at javascript search libraries, such as <a href="https://fusejs.io/">FuseJS</a>. This lightweight fuzzy search library makes searching an array of objects incredibly easy:</p><pre>let options = {<br>  keys: [&#39;title&#39;, &#39;description&#39;],<br>  id: &#39;id&#39;<br>}<br>let fuse = new Fuse(listings, options)</pre><pre>fuse.search(&quot;bake coffee cake&quot;)</pre><p>The upside of this solution is that you can keep using the very efficient $geoNear operator, and also implement a ‘smarter’ search functionality than a mere regular expression. This search library in particular will actually return results according to relevance, which is something you can’t do with regex.</p><p>Downside is that you are performing search operations on the server, instead of in the database itself, which is not the fastest or most efficient solution.</p><h3>Solution 5: search library in frontend</h3><p>Finally, there is also the possibility to implement the search functionality in the frontend of the application. Just like with solution 4, you also keep using the indexed (fast) $geoNear operator, and use the external search library to perform a text search, instead of using $text or a <a href="https://regexone.com/">regular expression</a> regex in the query.</p><p>Downside of doing this in the frontend is that more data has to be processed and sent, seeing that all the listings that meet the geospatial query have to be shipped to the frontend, before they can be searched. This will increase initial load time.</p><p>The upside of this solution, though, is that after the initial listings (those within range of the user) are loaded, many searches can be performed without having to reload any data. This could turn out to be more efficient and yield a better UX in the end.</p><h3>Conclusion:</h3><p>Personally, I ultimately decided to implement solution 5. This does mean that we initially load all the listings that are within range of the user, but that’s fine, because in our use case it is not much of a problem if users initially see a lot of things that they weren’t necessarily looking for. In fact, it can lead to serendipity, which is a beautiful thing that is actually likely to help us grow the platform.</p><p>Your use case may be entirely different, though, which is why only you can decide which solution is best for your project. In any case, I hope that me <a href="https://cornevanstraten.com/learning-out-loud/">learning out loud</a> about this has been helpful to you.</p><p>Good luck!</p><p><em>Originally published at </em><a href="https://cornevanstraten.com/mongodb-geosearch-1/"><em>https://cornevanstraten.com</em></a><em> on February 24, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3747cfe0104" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Curl mini-lesson: testing webhook]]></title>
            <link>https://cornvanstraten.medium.com/curl-mini-lesson-testing-webhook-234aeabfef6e?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/234aeabfef6e</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Thu, 28 Jan 2021 14:36:28 GMT</pubDate>
            <atom:updated>2021-05-14T19:02:46.872Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aoPBi-AFYk4esiVO" /></figure><p>Mini lesson regarding coding, this time about testing a webhook using curl.</p><h3>Situation:</h3><p>We’re using <a href="https://cornevanstraten.com/testing-webhook-api-with-curl/mux.com">Mux</a> for video processing at <a href="https://crash.co/">Crash</a>. The way this works (roughly) is:</p><ul><li>Us: “Hey mux, we’re about to upload something.”</li><li>Mux: “Cool, here’s an uploadId you can use to create a presigned upload URL”</li><li>Us: <em>create presigned upload URL</em></li><li>User: <em>uploads/streams to this presigned URL</em></li><li>Mux: <em>transcodes to high performance web asset as soon as the first bytes come in. Assigns a playbackId once the transcoding is ready.</em></li><li>Mux: <em>“</em>Your video is ready for playback!” (webhook)</li></ul><p>We were dealing with a small bug though, on our side, as a result of a <a href="https://en.wikipedia.org/wiki/Race_condition">race condition</a>: two separate calls in this sequence that are really close together (less than milliseconds apart) sometimes collide with each other.</p><p>The fix for this is not even that hard, but the problem comes in when trying to test the solution, seeing that I can’t expect Mux to now send webhooks to my localhost.</p><h3>Solution:</h3><p>There are services that can actually channel webhook calls to your localhost (e.g. <a href="https://ngrok.com/">ngrok</a>) but a way easier solution is to just mock the call by using curl.</p><p><a href="https://curl.se/">cURL</a> (client-url) is a command line interface with which you can send http-requests to any url.</p><p>A curl request always starts with curl and ends with the target domain (e.g. http://localhost:3000). You can add data to the request by using the --data or -d flag. A simple curl request could look like this:</p><pre>curl --data &quot;price=99&quot; localhost:3000</pre><p>In our case though, the webhook call comes with a JSON payload, in which case you need to add the --header flag saying &quot;content-type: application/json&quot;.</p><pre>curl --header &quot;content-type: application/json&quot; --data &#39;{&quot;type&quot;: &quot;video.asset.ready&quot;, &quot;object&quot;: { &quot;type&quot;: &quot;asset&quot;, &quot;id&quot;:&quot;B02dgt87Jv00mR3cpgcYtOZkIGz87aIZl9&quot;}}&#39; <a href="http://localhost:3001/webhooks/mux">http://localhost:3001/webhooks/mux</a></pre><p><em>Originally published at </em><a href="https://cornevanstraten.com/testing-webhook-api-with-curl/"><em>https://cornevanstraten.com</em></a><em> on January 28, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=234aeabfef6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Formik mini-lesson]]></title>
            <link>https://cornvanstraten.medium.com/formik-mini-lesson-603ffe9c626e?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/603ffe9c626e</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Thu, 17 Dec 2020 14:24:07 GMT</pubDate>
            <atom:updated>2021-10-25T19:27:54.720Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dJRr1KnkGiwjm079hmKnbA.jpeg" /></figure><p>Another mini lesson regarding coding, this time about Formik, a form-building library for React.</p><p>The application I work on uses <a href="https://formik.org/">Formik</a> for its forms.</p><blockquote><em>Formik is the world’s most popular open source form library for React and React Native. Formik takes care of the repetitive and annoying stuff-keeping track of values/errors/visited fields, orchestrating validation, and handling submission-so you don’t have to.</em></blockquote><h3>Situation:</h3><p>As a minor feature, our <a href="https://cornevanstraten.com/formik-mini-lesson/crash.co">app</a> allows users to specify up to two different location preferences — places where they’d be willing to work. You can specify specific cities, states, countries, ‘remote’ or just ‘anywhere’.</p><p>So the app allows you to add either one or two of these location preferences, but up until now, there was no option to <em>remove</em> a location preference. You could only alter them.</p><p>So that was my task: to make it possible to remove a location preference. Seems straightforward enough, right? I thought so too, but when I looked at the code, I couldn’t really make sense of it.</p><pre>let [, { value: firstLocation }, { setValue: setFirstLocation }] = useField( firstLocationPath ); let [, { value: secondLocation }, { setValue: setSecondLocation }] = useField( secondLocationPath );</pre><p>What I did understand was that the state of the locations was tied to their respective fields. But where was the parent, the array of locations? How do I access and alter it? Why is there no useState() hook with a setter function I can use?</p><p>Of course, I could use the setter function on the location to be deleted, and just set it to null, but then we&#39;d end up with an array with two elements, one of which is null.</p><pre>[ { type: LocationType.city, city: &#39;San Francisco&#39;, state: &#39;CA&#39;, country: &#39;United States&#39; }, null ]</pre><p>We could write code to handle that, but it’s far from elegant. So what’s going on here?</p><h3>Lesson:</h3><p>Formik uses its own state and ways to update it. When you open a form, Formik clones the state of the variables you’re using (in this case the locations) into its own form state. That means that this state can now be altered and updated independently, without it directly affecting the rest of the DOM.</p><p>When the form gets submitted, the form’s state gets sent to the server through an update mutation, the server takes care of updates in the database and sends updated fields back to React, after which React’s state gets updated. This way, the form’s state and the state in the app elsewhere never conflict, and there’s always a single source of truth.</p><p>To access the form’s state, you can use Formik’s useField() hook and specify the path to the particular field you&#39;re trying to target - in my case the locations array. You can <a href="https://formik.org/docs/api/useField">deconstruct helper functions from a </a>useField()<a href="https://formik.org/docs/api/useField"> hook</a> just like normal, to help you change a field&#39;s values.</p><p>So in my case, getting access to the locations parent array looked like this:</p><pre>let [, , { setValue: setLocationArray }] = useField( locationsPath );</pre><p>It’s worth noting that there is also a <a href="https://formik.org/docs/api/fieldarray">FieldArray component in Formik</a> that is intended for dealing with arrays like this, specifically. It comes with its own helper functions like push and remove which can be very handy.</p><p>In our case though, since we’re dealing with an array that will only ever have two elements maximum, I elected to keep it simple and stick with a standard useField() hook.</p><p><em>Originally published at </em><a href="http://cornevanstraten.com/formik-mini-lesson/"><em>https://cornevanstraten.com</em></a><em> on December 17, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=603ffe9c626e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tailwind specificity]]></title>
            <link>https://cornvanstraten.medium.com/tailwind-specificity-2c3394cd8a2c?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c3394cd8a2c</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Thu, 03 Sep 2020 21:03:47 GMT</pubDate>
            <atom:updated>2021-10-25T19:34:26.210Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wVqbjXbHokvFyrQp9N14bg.jpeg" /></figure><p>Tailwind is the CSS-framework we work with at <a href="https://crash.co/">Crash</a> (the company I work for).</p><blockquote><em>Tailwind CSS is a highly customizable, low-level CSS framework that gives you all of the building blocks you need to build bespoke designs without any annoying opinionated styles you have to fight to override.<br></em><a href="https://tailwindcss.com/"><em>Tailwindcss.com</em></a></blockquote><p>I already had a little experience with UI frameworks like <a href="https://getbootstrap.com/docs/3.4/">Bootstrap</a> and <a href="https://bulma.io/">Bulma</a>, but Tailwind works a little differently. Whereas other frameworks tend to come with a lot of default styling out of the box (like button and card classes), Tailwind only provides utility classes like text-lg and md:w-24.</p><p>The downside of this is obviously that you have to do a lot of the styling yourself, but the upside is that you don’t have to battle your framework, fighting specificity wars to override default classes whenever you want custom styles — which, in the case of <a href="https://cornevanstraten.com/code-lessons-1-tailwind-specificity/crash.co">Crash</a> is all the time.</p><h3>Situation:</h3><p>I was building a new feature that required a button that was styled to look like a simple text link. So I imported our custom Button React Component and passed it the text option under the appearance prop, that was supposed to make it look like plain text. So far so good.</p><p>The only problem was that the way this Button with appearance=&#39;text&#39; was styled, my button&#39;s text ended up exactly one pixel higher than all the actual links it was right next to.</p><p>So naturally, having experience with <a href="https://getbootstrap.com/">Bootstrap</a>, <a href="https://bulma.io/">Bulma</a> and CSS in general, I tried to override the classes that caused this with specificity. But then I ran into the oddest problems: <strong>with some classes, this would work, but for others it wouldn’t. </strong>😧</p><pre>{showArchiveLink &amp;&amp; ( &lt;&gt; &lt;span&gt;*&lt;/span&gt; &lt;Button type=&quot;button&quot; unstyled className=&quot;hover:underline leading-3 justify-center&quot; onClick={() =&gt; archivePitch({ variables: { id: pitch.id } })} &gt; Archive Pitch &lt;/Button&gt; &lt;/&gt; )}</pre><p>I tried to find some common denominator, but I couldn’t find out why, until our lead developer Dave explained it to me.</p><h3>Lesson:</h3><p>Trying to override classes with specificity doesn’t work in Tailwind because <strong>all Tailwind’s classes have a specificity of one</strong>. This means that the definition order determines which class wins out in the case of conflict: <strong>whichever one was defined later applies</strong>.</p><p>This explains why trying to override classes with other classes would work sometimes, but not all the time.</p><p>Rather than overriding classes with specificity, like you do in other frameworks, Tailwind actually forces you to actively remove classes in cases like this.</p><p>So that’s what I ended up doing. I rewrote the Button component and its styles to account for a completely un-styled option, then imported that.</p><p>Although annoying in the moment, this behavior by Tailwind actually enforces good design patterns in this way, so it’s a smarter idea for the long term.</p><p>Score 1 for Tailwind.</p><p><em>Originally published at </em><a href="http://cornevanstraten.com/code-lessons-1-tailwind-specificity/"><em>https://cornevanstraten.com</em></a><em> on September 3, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c3394cd8a2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cutting political news consumption]]></title>
            <link>https://cornvanstraten.medium.com/cutting-political-news-consumption-f289239b90d7?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f289239b90d7</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 23:19:00 GMT</pubDate>
            <atom:updated>2021-06-16T18:08:16.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ojF_ltTHdxHRlwea" /></figure><p>Over the last 3 years, I’ve seriously cut back on my consumption of political news and I can really, really recommend it.</p><p>There is so much stuff going on in politics that is, admittedly, horribly infuriating, but that at the same time we can’t even begin to have any meaningful influence over.</p><p>By cutting back on consuming political news I have mostly saved myself a lot of frustration and emotional energy, but I’ve also saved a ton of time.</p><p>I try to spend that time by either being more productive and learning new skills, or by doing something truly relaxing.</p><p>This approach has seriously improved my quality of life, which I’m really happy about.</p><p>I thoroughly recommend it!</p><p><em>Originally published at </em><a href="https://cornevanstraten.com/cutting-political-news-consumption/"><em>https://cornevanstraten.com</em></a><em> on June 22, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f289239b90d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to detect your own chrome extension]]></title>
            <link>https://cornvanstraten.medium.com/how-to-detect-your-own-chrome-extension-38da6313b89c?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/38da6313b89c</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Thu, 18 Jun 2020 01:21:20 GMT</pubDate>
            <atom:updated>2022-01-18T20:58:28.833Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NZh0l1kYpXSQSHgKEJb2g.jpeg" /></figure><p>A little while ago, I developed and <a href="https://cornevanstraten.com/how-i-made-my-first-chrome-extension/">published my first chrome extension</a>. Now that it’s gone through a few iterations, we want to start pushing it more from the main web application, so we need to detect whether or not users already have it installed. Here’s how.</p><h3>Use case</h3><p><a href="https://crash.co/"><strong>Crash</strong></a> is a pitching platform for winning jobs. The web app allows users to create <a href="https://crash.co/hall-of-fame">custom video pitches</a> and send them straight to the hiring manager, yielding a very high (50–80%) conversion rate in terms of interviews won.</p><p>The <a href="https://chrome.google.com/webstore/detail/crash-pitch-tool-beta/njicebecehmpjfanalngegpgmgllpaim?hl=en">chrome extension</a> allows users to start creating pitches from anywhere on the web, so that whenever they find a job opening on some job board, they’re only one click away from a new pitch for that job.</p><p>Now, whenever our users are on their dashboard in the web app, we want to remind them that they can download the extension, if they haven’t already.</p><h3>High level conceptual overview</h3><p>It’s important to understand that you cannot detect the presence of a browser extension in a user’s browser directly — most likely for privacy reasons. However, you can set up your own extension to be detected by websites (domains) of your choosing.</p><p>The way this works, conceptually, is relatively straightforward. The web application sends a message to the extension to see if it’s installed (requesting the version number, for example) and if the extension sends the expected response, you know that it is.</p><h3>Setting up the extension</h3><p>To set this up, first you have to make sure you have a background script in your extension.</p><p>Your background script is the only script in your chrome extension that runs when the extension is not opened. And seeing that the extension is most likely not opened while you’re checking if it’s installed, you need to communicate with the background script (and not with the content script or popup script).</p><p>If you have to add a background script for this particular use case, add the following to your manifest.json file:</p><pre>&quot;background&quot;: { &quot;scripts&quot;: [&quot;background.js&quot;], &quot;persistent&quot;: false },</pre><p>Now, messaging between web pages and the extension works very similarly to <a href="https://cornevanstraten.com/how-i-made-my-first-chrome-extension/">messaging between content scripts and popup scripts</a>, namely via the chrome.runtime messaging API.</p><p>The difference is that web pages don’t have access to that messaging API by default. You need to explicitly give them that permission, by adding the following to manifest.json:</p><pre>&quot;externally_connectable&quot;: { &quot;matches&quot;: [&quot;*://localhost/*&quot;] },</pre><p>Obviously, you want to <a href="https://developer.chrome.com/extensions/messaging#external-webpage">add your own domain</a> under matches (in our case: <a href="https://crash.co/">crash.co</a>) if you’re running the app in production, but localhost works for testing purposes.</p><p>Now in background.js, add the following line to receive messages from the allowed domain:</p><pre>chrome.runtime.onMessageExternal.addListener();</pre><p>Note the onMessageExternal instead of the regular onMessage, here.</p><p>My implementation in background.js looks like this:</p><pre>chrome.runtime.onMessageExternal.addListener(gotMessageExternal); </pre><pre>function gotMessageExternal(message, sender, sendResponse) { <br>   if (message.txt === &#39;req version&#39;) { <br>      const manifest = chrome.runtime.getManifest(); <br>      sendResponse({ type: &#39;success&#39;, version: manifest.version, });    <br>   } <br>}</pre><h3>Setting up the web app</h3><p>Now that the extension is set up to receive and send messages, you can start sending messages from your web app to detect whether the extension is installed.</p><p>To do this, you need your extension’s ID. If you don’t know the ID, you can go to chrome://extensions in your browser and find it there, or just take the ID directly from the URL of your extension in the Chrome Web Store.</p><p>When you have the ID, you can just start sending messages right from the script on the page where that information is relevant.</p><p>An implementation could look like this:</p><pre>const EXTENSION_ID = &#39;bphcnpchmidlijnafkkjaddhadmildfh&#39;; </pre><pre>chrome.runtime.sendMessage( EXTENSION_ID, { txt: &#39;req version&#39; }, response =&gt; { <br>   if (!response) { //display popup: download the extension return }   <br>   console.log(&#39;Extension version: &#39;, response.version); <br>});</pre><p>And that’s all there is to it!</p><p>Hopefully, my <a href="https://cornevanstraten.com/tag/learn-out-loud/">learning out loud</a> here has been useful to you. Have a great day, and happy coding!</p><p><em>Originally published at </em><a href="https://cornevanstraten.com/how-to-detect-your-chrome-extension/"><em>https://cornevanstraten.com</em></a><em> on June 18, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38da6313b89c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I made my first chrome extension]]></title>
            <link>https://cornvanstraten.medium.com/how-i-made-my-first-chrome-extension-530da00392a1?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/530da00392a1</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Wed, 08 Apr 2020 03:18:13 GMT</pubDate>
            <atom:updated>2021-06-16T18:15:58.014Z</atom:updated>
            <content:encoded><![CDATA[<p>I made a first version of a chrome extension for crashers, i.e. job seekers that are using the <a href="https://crash.co/">crash.co</a> job hunting tool. This tool will make it easier for these job hunters to use Crash to pitch jobs they find anywhere on the web.</p><p>So the purpose of this particular extension is to make it easy to pitch a job using job hunting platform <a href="https://crash.co/"><strong>Crash</strong></a>.</p><blockquote>If you’re unfamiliar, the idea behind <a href="https://crash.co/">Crash</a> is that, if you want to win a job, making a tailored video pitch with proof of work and skills is superior to any cover letter and resume. Check it out if there is more to you than a list of bullet points can express.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yIDlsyBg8pP9CzYmMEVnPA.gif" /></figure><h3>Basic anatomy of the chrome extension :</h3><p>Every chrome extension has a basic anatomy in order for it to work properly. Let’s go over the different items real quick:</p><h3>Manifest.json</h3><p>First thing you need is manifest.json file. Similar to a package.json in NodeJS, this file describes your project and its contents.</p><p>Here’s the manifest.json for this project:</p><pre>{ <br>&quot;manifest_version&quot;: 2, <br>&quot;name&quot;: &quot;Crash pitch tool&quot;, <br>&quot;description&quot;: &quot;Beta&quot;, <br>&quot;version&quot;: &quot;0.1.0&quot;, <br>&quot;icons&quot;: { &quot;128&quot;: &quot;icon.png&quot; }, <br>&quot;browser_action&quot;: <br>  { <br>    &quot;default_icon&quot;: &quot;icon.png&quot;, <br>    &quot;default_popup&quot;: &quot;popup.html&quot; <br>}, <br>&quot;permissions&quot;: [&quot;activeTab&quot;], <br>&quot;content_scripts&quot;: <br>  [ { &quot;matches&quot;: [&quot;&lt;all_urls&gt;&quot;], &quot;js&quot;: [&quot;content.js&quot;] } ] <br>}</pre><p>Next thing is a content script. A content script is javascript that will execute when the page loads. You can use it to manipulate that page. It will only load if the URL matches the ones provided in the manifest.</p><p>By default, the content script will only start running once the page is loaded, which is really convenient.</p><h3>Background script</h3><p>There is also the background script, which is always running, and starts running as soon as you launch chrome. The background script listens for all the events that are happening in and around the <em>chrome browser</em>, such as opening a new tab or typing in the address bar.</p><p>Keep in mind that, because the background script is running in chrome and not on the page, you cannot debug the background script using the same console.</p><p>In this first version of this extension, I actually don’t need a background script yet.</p><h3>Popup</h3><p>A chrome extension does not require a popup, but you can have one pop up on clicking the icon, defined under browser_action: default_popup. This is just a simple HTML file for which you can set scripts and stylesheets separately. It is most commonly displayed as an overlay over the current tab.</p><p>It’s important to note that this popup, with its HTML and (optional) scripts and stylesheets will load fresh every time you click the button.</p><h3>How it works</h3><p>So the purpose of this extension is to make it easy to save some essential information from the job listing page and use it in the <a href="https://crash.co/">Crash</a> pitch editor, in a Pinterest-like fashion.</p><p>The data I’m looking for is:</p><pre>Company name Company domain Job title Hiring Manager URL</pre><p>In this first version, the user will still have to copy the first four items from the job listing itself, but the URL is automatically populated behind the scenes.</p><p>Now, seeing that the URL of the current job posting tab can only be accessed from the content script, and not from within my extension itself, I need to make sure I get that data from content.js to my popup.js script.</p><p>So from popup.js, the script in my extension, I send the request for the URL to the currently active tab, and wait for the response to update the URL using the following code:</p><pre>chrome.tabs.query( { active: true, currentWindow: true }, function (tabs) { chrome.tabs.sendMessage(tabs[0].id, { txt: &quot;req URL&quot; }, function (response) { //update the URL }); });</pre><p>In the content.js script, I make sure I receive the message and send back the URL of the current tab in response:</p><pre>chrome.runtime.onMessage.addListener(gotMessage); function gotMessage(message, sender, sendResponse) { const currentURL = window.location.href; sendResponse({ url: currentURL }); }</pre><p>Then the only thing left to do is to make sure the link that the “pitch it” button leads to is updated on every input change. To do this, I add an event listener to every input with a forEach loop:</p><pre>document.querySelectorAll(&quot;.input&quot;).forEach((item) =&gt; { item.addEventListener(&quot;change&quot;, updateButton); });</pre><p>And that is all there is to it (so far). Find the full project on GitHub at <a href="https://github.com/cornevanstraten/crash-extension"><strong>github.com/cornevanstraten/crash-extension</strong></a></p><p><em>Originally published at </em><a href="https://cornevanstraten.com/how-i-made-my-first-chrome-extension/"><em>https://cornevanstraten.com</em></a><em> on April 8, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=530da00392a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why most nutrition science is garbage]]></title>
            <link>https://cornvanstraten.medium.com/why-most-nutrition-science-is-garbage-8ca678c03beb?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ca678c03beb</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Tue, 25 Feb 2020 17:10:19 GMT</pubDate>
            <atom:updated>2021-06-16T18:17:27.546Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cMHlSeW9HcPLZmls" /></figure><p>Imagine you wanted to know which phone was faster: the iPhone 11 or the Samsung Galaxy S20.</p><p>But instead of setting up an experiment with tests, you decided to find the answer by surveying a couple thousand people, asking them to rate their phone’s performance on a scale from 1–5; and base your conclusion on those results.</p><p>Sounds pretty stupid, doesn’t it?</p><p>Yet, this is what almost all studies on health and nutrition are like!</p><p>They’re <a href="https://en.wikipedia.org/wiki/Epidemiology">epidemiological</a>, i.e. not based on experimentation, but on surveys — people filling out questionnaires about what they ate over the last X number of months and rating how they feel.</p><p>Remember that the next time somebody claims that a certain food is “scientifically proven” to be good/bad for you.</p><p>Experimentation &gt; questionnaires</p><p><em>Originally published at </em><a href="https://cornevanstraten.com/why-nutrition-science-is-mostly-garbage/"><em>https://cornevanstraten.com</em></a><em> on February 25, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ca678c03beb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What coding taught me about culture]]></title>
            <link>https://cornvanstraten.medium.com/what-coding-taught-me-about-culture-b89ab644d6f1?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b89ab644d6f1</guid>
            <category><![CDATA[culture]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Wed, 05 Feb 2020 15:01:58 GMT</pubDate>
            <atom:updated>2020-02-05T15:01:58.818Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8z-VDDzyvrVkg1ucIoS6Rw.jpeg" /></figure><p>Culture is this unquantifiable, nebulous concept. Elusive, devoid of hard facts, definitions and data. As such, it’s is a subject I would typically shy away from. Because I’m someone who feels way more drawn to the objective, the binary, the hard truths and the unbreakable rules. Like the world of code. So it’s pretty ironic that teaching myself how to program has actually taught me how to appreciate culture. Here’s why.</p><p>Let’s start by answering this question:</p><h3>What is culture?</h3><p>Culture is actually incredibly hard to define. If I had to take a stab at it, though, I would say that culture is:</p><blockquote>The way a certain group of people does things.</blockquote><p>I know this definition is incredibly vague, but, in my defense, so is culture itself. In fact, culture is so vague that it’s pretty much invisible. I would go so far as to say that this is the one distinctive factor about culture. A culture is generally invisible to the people that are part of that culture.</p><p>The reason for that is that culture is made out of <a href="https://cornevanstraten.com/tacit-knowlege/">tacit knowledge</a>. Information that people ‘just know’. It’s not written down anywhere, because nobody would even think to write it down. By definition, it’s obvious to the people that are part of that context.</p><p>To illustrate this, let’s think of five simple scenario’s:</p><ol><li>Visiting a friend’s house</li><li>Work meeting</li><li>Sales meeting with the CFO of prospective new client</li><li>Dinner with your significant other’s parents</li><li>Wedding</li></ol><p>For each of these scenario’s, answer the following questions: What are you wearing? Should you bring a gift? Is it okay to say you can’t make it? What are appropriate/inappropriate topics of conversation? What kind of jokes are okay, if any? Is it okay to refuse food that is offered to you? Can you open your phone or laptop at any point during conversation?</p><p>It’s not too hard to answer these questions if the scenarios are taking place in your own culture. Now imagine these scenarios again, but now you’re in France, Ghana, China or Russia. Not so easy now, is it?</p><h3>So how did code, of all things, teach me about this topic?</h3><p>To answer that question, let’s start with a definition again. What is code? Unlike culture, code is actually really easy to define:</p><blockquote><em>Code is a set of instructions to make a computer do something.</em></blockquote><p>Sounds simple enough. But the thing about this set of instructions is that it needs to be <em>highly, highly</em> specific. And this is because a computer has no understanding. It can only do what it is specifically told to do and nothing else.</p><p>If you’re not specific enough in your code, that’s going to result in errors, bugs and all kinds of other problems down the road.</p><p>It’s hard to appreciate exactly how specific this set of instructions needs to be if you’ve never coded anything in your life, so here’s an excerpt from <a href="https://atomic55.net/programming-vs-making-a-cup-of-tea/">an article that explains it perfectly</a>.</p><pre>When you ask non-programmers to describe the steps needed to make a cup of tea, they will say something like:</pre><pre>- boil water<br>- put tea in a pot<br>- when the water is boiled pour it into the pot<br>- wait 5 mins<br>- pour the tea into cups<br>- drink</pre><pre>Now the fun begins. You need to start asking these kinds of questions:</pre><pre>Boil water? Where is the water coming from? Where is the kettle? How do you get the water into the kettle? How do you know how much water to put into the kettle? What if there is already water in the kettle? What does it mean for the water to be boiling? How do I know if the water is boiling? </pre><pre>Etc.</pre><p>So as you can see, this seemingly simple set of instructions to make tea actually presupposes a ton of knowledge. And in coding, you can’t presuppose any knowledge, because a computer doesn’t understand anything other than what you have specifically told it.</p><p>If your code says to import a file from ./styles/style-sheet.css/ but you should have said ./styles/style_sheet.css/ it will never find that file for you, even if it&#39;s literally the only file in that folder.</p><p>Worse, it will only let you know that it can’t find it after it tries to run your code and throws an error. This is your computer’s TL;DR version of saying that it expected one thing, but experienced another, so it panicked and crashed into a tree.</p><h3>Migration</h3><p>Culture consists largely of <a href="https://cornevanstraten.com/tacit-knowlege/">tacit knowledge</a> and unspoken expectations, largely born out of shared experiences between the people that make up that culture. This shared understanding makes sure that not everything has to be spelled out in minute detail. And the fact that you don’t have to be highly specific in everything you say removes a lot of friction in society. It makes daily life run smoothly.</p><p>However, when you migrate into a new culture, you lack at least some of this <a href="https://cornevanstraten.com/tacit-knowlege/">tacit knowledge</a>, because you don’t share the same experiences as the people who are already part of this culture.</p><p>Whether you’re migrating to a new country, a new business/industry, a new family, a new sport, or whatever else it might be, whenever you’re moving into a culture that’s unfamiliar to you, you’re like a computer trying to run a program that has some code missing.</p><p>Nobody tells you how you’re expected to do things for the same reason that you don’t think to ask. Culture is too obvious to discuss… until something goes wrong. So, like a computer, you’re totally unaware of what information you’re missing until you run into a situation where you don’t know what to do.</p><p>To some people, this is all part of the charm of traveling, or generally engaging with people from another culture.</p><p>For others, it’s added friction that just creates unnecessary problems.</p><p>I understand both perspectives.</p><p>But, as an immigrant myself, I would ask you this. Whenever you do run into a misunderstanding with someone from a different culture, comical or not, just remember. It’s not rude. It’s not personal.</p><p>It’s like your computer giving you an error.</p><p>It’s just unexpected behavior.</p><p><em>this article was originally published at </em><a href="https://cornevanstraten.com/"><em>cornevanstraten.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b89ab644d6f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meta communication, or how to deal with confrontation productively]]></title>
            <link>https://cornvanstraten.medium.com/meta-communication-or-how-to-deal-with-confrontation-productively-6693718c5f23?source=rss-7abe1add283f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6693718c5f23</guid>
            <dc:creator><![CDATA[Corné van Straten]]></dc:creator>
            <pubDate>Wed, 04 Dec 2019 04:11:19 GMT</pubDate>
            <atom:updated>2021-06-16T18:34:42.565Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t50XnEew3S6X-PaA7eBZBQ.jpeg" /></figure><p>Offensive questions, disrespectful remarks — dealing with lose-lose confrontation can be incredibly difficult, especially when you feel defensive. Luckily, there are tools that can help you deal with confrontation productively.</p><p>Here’s how:</p><p>I recently came across a young mother with a problem. After a lot of research and consideration, she had chosen to take the <a href="https://tendinglambs.com/what-is-gentle-parenting/">gentle parenting</a> approach towards raising her baby. But now, as a result of her decision, she had to deal with constant judgement and unsolicited advice on a daily basis.</p><p><em>“The umbilical cords was cut at birth, your baby needs to sleep in her own room” “Are you ever gonna put that baby down?”</em></p><p>It’s never easy to deal with this type of confrontation and criticism, especially when it’s from within your own social circle.</p><p>But it’s absolutely essential that you say something about it, because <strong>you train people how to treat you</strong>. If you let people talk to you a certain way, you’re teaching them that it’s okay and they will keep doing it.</p><p>At the same time, though, you don’t want to get into a fight every time somebody mentions something like this either, so you need a smart way to deal with it. That smart way is <em>meta </em>communication.</p><p>I suggested the following meta response to this young mother:</p><blockquote><em>“I appreciate your concern for me and my baby, but I have made my choices carefully. If the situation changes and I need a different opinion, I will come find you, but until then I’d appreciate it if you respected my choices. Alright?”</em></blockquote><p>And if they still keep going:</p><blockquote><em>“Thanks, but like I said, I’ve made my choices carefully. And it is frankly quite frustrating to constantly be pushed a different direction than what I believe is right for my family. It does not make me feel respected as a parent.”</em></blockquote><p>Now you might say that it’s easy to come up with a response like this from the comfort of an armchair, and that it’s a lot more difficult when you have to do it in the heat of the moment.</p><p>And that is absolutely true!</p><p>I was not the one being criticized and I had time to think about a good response, so it was definitely a lot easier for me.</p><p>But trust me that it <em>is</em> actually possible to come up with a good and productive response like this on the spot, because there is a formula to it. And all you have to do is keep calm and apply the formula.</p><p>The way it works is as follows. Instead of addressing the question or criticism directly, you talk about the subject on a more meta level, using one (or a combination) of these three approaches:</p><ol><li>Talking about the communication itself</li><li>Addressing relational aspects</li><li>Describing a process you are subject to</li></ol><p>All these approaches will help you avoid traps and elevate the conversation to a more productive level. Let’s look at each of them in more detail.</p><h3>1. Talking about the communication itself</h3><p>In this approach, you will be talking <em>about </em>the question you were asked or the criticism leveled against you, without <em>answering</em> it directly.</p><p>You have many different options here. You can point out how:</p><ul><li>certain claims are unsubstantiated</li><li>assumptions are unfounded</li><li>terms are not defined</li><li>something is not clear</li><li>bias is shown</li></ul><p>For example:</p><p><strong>Question: </strong><em>People say that you as the leader of this organization have made a lot of mistakes and that you are therefore to blame for the bankruptcy. How could you let this happen?</em></p><p>This question is clearly putting you on the defensive. No matter how good your explanation is for the choices you made in the past, they turned out wrong so you’re going to look weak. A <em>meta</em> answer to this question could save you here, though, by talking about the question itself:</p><p><strong>Meta answer:</strong> <em>From your question I conclude that you take this as a matter of fact, but I do not see any substantiation for it. In any case, I think it would be better if we focused on the facts instead of on matters of opinion.</em></p><h3>2. Relational aspects</h3><ul><li>This is how I see the power structure between us</li><li>This is how I understand your message and how I feel about it</li><li>This is how I want to be seen and how you should feel about me</li></ul><p>The relational aspects of conversation entail everything concerning the relationship between you and your conversation partner. It’s communicating how a message should be received — often without additional words.</p><p>For example, the people criticizing the young mother I mentioned earlier, also communicated with their criticisms that they felt like they were in a position of power/authority over her, that they disapproved of her approach and that they wanted to be seen as superior at parenting.</p><p>All these relational aspects provide angles to approach a meta response from, simply by putting it into words.</p><p>Alternatively though, you could calmly communicate how you understand a message and how it makes you feel (sad, frustrated, disrespected, misunderstood). This is always a great way to go.</p><p>Reiterating the example I gave earlier:</p><blockquote><em>“It is frankly quite frustrating to constantly be pushed a different direction than what I believe is right for my family. It does not make me feel respected as a parent.”</em></blockquote><p>99% of people will back off when you tell them point blank that the way they’re treating you makes you feel disrespected. The only thing you need is the courage to actually say it.</p><h3>3. Describing a process you are subject to</h3><p>My favorite approach and probably the least confrontational of the three, is describing a process. Although this approach can not be applied in every single situation, you can still apply it surprisingly often.</p><p>Another example to illustrate:</p><p><strong>Question: </strong><em>You don’t think there is any chance that </em>you<em> will get that promotion, do you? I’ve worked here for way longer than you, and I also have a lot more experience in general.</em></p><p>This is clearly a lose-lose situation. If you answer in the affirmative, you will look weak; but if you counter by mentioning your superior leadership skills, you will only fuel the discord. Here again, you can diffuse the situation by using meta communication, this time by describing a process step by step:</p><p><strong>Meta answer: </strong><em>We have both been invited to interview for this position, so it seems that the final decision has not yet been made. Which one of us ultimately will get the job will undoubtedly only be decided after the interview process. So we’re going to have to wait until after the interviews and see what the management board decides.</em></p><p>The great thing about this approach is that you only state the facts of the situation that nobody can disagree with. Also, by describing a process, you put both yourself and your conversation partner in a passive position, subject to an external system that will generate some outcome at a later date. This way, you completely absolve yourself of the responsibility to even answer the question at this time.</p><p>This tactic is frequently employed by politicians, trying to dodge questions about their disappointing polling numbers, for example.</p><p>Confrontation is something we all have to deal with every now and then, both in business and in life. And although <a href="https://cornevanstraten.com/life-lessons-from-rugby/">dealing with confrontation head on</a> can sometimes be helpful, lose-lose games should always be avoided.</p><p>Meta communication can be a great tool to avoid such games and elevate communication to a more productive level.</p><p>Applying these techniques can save you a lot of discord, so give it a try!</p><p><em>Originally published at </em><a href="https://cornevanstraten.com/metacommunication-or-how-to-deal-with-trap-questions/"><em>https://cornevanstraten.com</em></a><em> on December 4, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6693718c5f23" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>