<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sai Chimata</title>
    <description>The latest articles on DEV Community by Sai Chimata (@bread-and-roses).</description>
    <link>https://dev.to/bread-and-roses</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F233814%2F7d2311bd-8762-4a61-b481-abf5e4161bfb.jpeg</url>
      <title>DEV Community: Sai Chimata</title>
      <link>https://dev.to/bread-and-roses</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bread-and-roses"/>
    <language>en</language>
    <item>
      <title>Thank Me Later: Use Styled Components's css helper everywhere</title>
      <dc:creator>Sai Chimata</dc:creator>
      <pubDate>Sat, 27 Jun 2020 21:59:53 +0000</pubDate>
      <link>https://dev.to/bread-and-roses/thank-me-later-use-styled-components-s-css-helper-everywhere-2ni1</link>
      <guid>https://dev.to/bread-and-roses/thank-me-later-use-styled-components-s-css-helper-everywhere-2ni1</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Anyone who has used Styled Components, that popular, powerful CSS-in-JS library, for any length of time has come across odd bugs that involve the renderer completely ignoring a style or several, sometimes for an entire component, initiating a frantic search for the root of the problem. I'll spare you the trouble: the culprit is often nested interpolation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nestedInterp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
   color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;black&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;white&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;;
   &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="cm"&gt;/*
      Without the `css` helper, the above function is cast as a string. 
     */&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Div&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
   &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;color: red;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;nestedInterp&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a caveat that beginners often stumble upon instead of read about, as syntactic sugar is meant to be inconspicuous. Template literals cast all interpolated values to strings, thus interpolated functions normally yield empty strings. Interpolated functions work as they do with Styled Components because the &lt;code&gt;styled&lt;/code&gt; object's members are tagged templates that provide that functionality. However, as with template literals, the returned values of interpolated functions are cast as strings. This means that nested interpolated functions are cast as well. For more information, read about &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" rel="noopener noreferrer"&gt;how string interpolation and tagged templates work "under-the-hood."&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Solution&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To solve this, Styled Components added &lt;a href="https://styled-components.com/docs/api#css" rel="noopener noreferrer"&gt;a helper function named simply &lt;code&gt;css&lt;/code&gt;&lt;/a&gt; that also accepts a tagged template as its parameter. It forwards props to any interpolations and handles any interpolated functions, just like &lt;code&gt;styled&lt;/code&gt;. In addition, many devs working with Styled Components will configure their linters to detect and resolve neglected nested interpolations. Unfortunately, linters are not fool-proof and edge cases often pop up in complex, destructured, deeply-nested UI component libraries. &lt;/p&gt;

&lt;p&gt;Thus, the developer community has recommended using the &lt;code&gt;css&lt;/code&gt; helper function for every nested template literal, whether or not the literal includes an interpolated function. In addition to the issues of unhandled nested interpolations and difficult-to-lint edge cases, this best practice resolves a number of &lt;a href="https://github.com/styled-components/styled-components-website/issues/209#issuecomment-358996796" rel="noopener noreferrer"&gt;other concerns&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/zooniverse/front-end-monorepo/issues/1469#issuecomment-580792105" rel="noopener noreferrer"&gt;Memory leaks in server-side rendered apps&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Providing a target to syntax highlighters and linters.&lt;/li&gt;
&lt;li&gt;Minification and transpilation.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/cssinjs/istf-spec" rel="noopener noreferrer"&gt;Future-proofing for interoperability and precompilation&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>ui</category>
      <category>css</category>
    </item>
    <item>
      <title>Quit looking down on non-STEM fields</title>
      <dc:creator>Sai Chimata</dc:creator>
      <pubDate>Fri, 22 Nov 2019 19:11:58 +0000</pubDate>
      <link>https://dev.to/bread-and-roses/quit-looking-down-on-non-stem-fields-2jh4</link>
      <guid>https://dev.to/bread-and-roses/quit-looking-down-on-non-stem-fields-2jh4</guid>
      <description>&lt;h4&gt;
  
  
  Those who are actually dedicated to the sciences often have a lot of respect for the arts and humanities, in my experience.
&lt;/h4&gt;

&lt;p&gt; – &lt;a href="https://twitter.com/ConnorSouthard" rel="noopener noreferrer"&gt;@ConnorSouthard&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's something most people don't know: "liberal arts" actually encompasses non-applied sciences like math and physics. Even &lt;strong&gt;computer science&lt;/strong&gt; is at its core a liberal arts field which is why the Department of Computer Science at my alma mater, Pitt, had been administered under the same school as the departments of linguistics and history. &lt;/p&gt;

&lt;p&gt;The term "liberal arts" comes from the Middle Ages when serfdom and slavery still existed, and the Latin-derived word "arts" was roughly equivalent to the Germanic "skill." These "arts" – originally arithmetic, geometry, astronomy, music theory, grammar, logic, and rhetoric – were seen in the Roman era as essential to participating in civic life as a free (i.e. liberated) person. In the Medieval era, they were understood as "liberating" man from peasantry. That connotation of "socioeconomic uplift" has of course continued into the present-day. &lt;/p&gt;

&lt;p&gt;The funny thing is that &lt;a href="https://www.edge.org/response-detail/23786" rel="noopener noreferrer"&gt;there are parallels between the anti-intellectualism of today and the beginnings of the "Dark Ages."&lt;/a&gt; Something that a lot of people misunderstand is that the Dark Ages weren't really imposed by barbarian invasions. In fact, these trends had &lt;em&gt;started&lt;/em&gt; within the Roman, and later Western Roman and Byzantine, Empire as a result of the Church denouncing liberal education (in the classical sense) as heresy. The Dark Ages were a &lt;em&gt;choice,&lt;/em&gt; not an imposition.&lt;/p&gt;

&lt;p&gt;The point of my history lesson is that liberal arts and non-STEM work and education form the foundation of all we do in the modern world. These disciplines underpin STEM fields and guide them. They aren't somehow discrete and separate. If we reject and devalue them, we risk falling into the same spiral of ignorance; this time an ignorance of democracy, liberty, justice, our history, things we take for granted.&lt;/p&gt;

&lt;p&gt;One of the mainstays of the modern tech industry is open source software. Open source has its philosophical underpinnings in the free software movement which applied enlightenment political philosophies and &lt;a href="https://en.wikipedia.org/wiki/Futures_studies" rel="noopener noreferrer"&gt;futures studies&lt;/a&gt; to the world of computers. Early proponents of open-source (including Tim O'Reilly, the author of the article I linked to on anti-intellectualism) saw its power in enabling innovation and applied it to software outside of the realm of GNU and similar projects.&lt;/p&gt;

&lt;p&gt;Proprietary software has its place to be sure, but some use-cases just don't make practical sense. Take electronic medical records, for example. One of the worst aspects of modern EMR systems is the lack of interoperability which causes untold amounts of headache for doctors and hospitals and can result in serious physician errors. It also results in software lock-in which removes competition, the main pricing mechanism of a market system, and drives up the costs of the healthcare. &lt;/p&gt;

&lt;p&gt;Another use case where proprietary software doesn't make sense is, of course, the Internet. Without open source software, none of &lt;strong&gt;this&lt;/strong&gt; would be possible! Imagine if the current TCP/IP ecosystem had developed around Gopher, instead of HTTP. Imagine every protocol, programming language, framework, browser, etc, being proprietary. Development would happen at a snail's pace. Zero-day hacks would be rampant. Operating costs would increase. This very site is written in Ruby, JavaScript, CSS, and HTML, run on Rails, Preact, and Node, and in all likelihood using Linux-based servers. It's distributed on a network defined by open standards like TCP/IP, DNS, HTTP(S), etc. If open source had never caught on, the Internet as we know it would've been a completely different place with nowhere near the current level of sophistication. &lt;/p&gt;

&lt;p&gt;All of this came about because an applied science was examined through a lens of sociology, economics, and political science. Not to mention, linguistics and logic underpin computer science and led to the development of the programming languages we know and love today. &lt;/p&gt;

&lt;p&gt;The arts and humanities are valuable tools to direct the implementation of technology. Even if you eschew and ridicule them, they still underpin your worldview and your craft.&lt;/p&gt;

</description>
      <category>education</category>
      <category>inclusion</category>
      <category>stem</category>
      <category>humanities</category>
    </item>
  </channel>
</rss>
