{"@attributes":{"version":"2.0"},"channel":{"title":"Chris Krycho - python","link":"http:\/\/v4.chriskrycho.com\/","description":{},"lastBuildDate":"Sun, 28 Feb 2016 12:50:00 -0500","item":[{"title":"Static Site Generators and Podcasting","link":"http:\/\/v4.chriskrycho.com\/2016\/static-site-generators-and-podcasting.html","description":"<p>Presently, I publish both <a href=\"http:\/\/www.winningslowly.org\/\">Winning Slowly<\/a> and <a href=\"http:\/\/www.newrustacean.com\/\">New Rustacean<\/a><a href=\"#fn1\" class=\"footnote-ref\" id=\"fnref1\" role=\"doc-noteref\"><sup>1<\/sup><\/a> using what is admittedly a bit of a quirky approach. It works well for me, and I think it\u2019s worth documenting for other nerdy types out there, but if you\u2019re just getting going with podcasting and you\u2019re looking for the easy way to do it, let me warn you: <em>this isn\u2019t it<\/em>. Something like <a href=\"https:\/\/soundcloud.com\/for\/podcasting\">SoundCloud<\/a> and a blog for show notes, or <a href=\"https:\/\/wordpress.org\">WordPress<\/a> with <a href=\"https:\/\/wordpress.org\/plugins\/powerpress\/\">Blubrry PowerPress<\/a> is what you want instead. This approach works <em>extremely<\/em> well for statically-generated sites, however, and I imagine a few people out there might find it useful.<\/p>\n<section id=\"the-short-version\" class=\"level2\">\n<h2>The short version<\/h2>\n<ul>\n<li>Generate the feeds with <a href=\"http:\/\/reinventedsoftware.com\/feeder\/\">Feeder<\/a>.<\/li>\n<li>Generate the site statically with something else (and it <em>really<\/em> doesn\u2019t matter what).<\/li>\n<li>Copy the feed into the generated site.<\/li>\n<\/ul>\n<\/section>\n<section id=\"the-long-version\" class=\"level2\">\n<h2>The long version<\/h2>\n<p>I generate the sites themselves with <a href=\"http:\/\/docs.getpelican.com\/en\/3.6.3\/\">Pelican<\/a> and <a href=\"http:\/\/www.newrustacean.com\/show_notes\/e001\/index.html\"><code>cargo doc<\/code><\/a>, respectively. I was already comfortable with Pelican because it\u2019s what I use to generate <em>this<\/em> site (with a few <a href=\"https:\/\/github.com\/chriskrycho\/chriskrycho.com\/blob\/master\/pelicanconf.py\">tweaks<\/a> to the standard configuration, especially using <a href=\"http:\/\/pandoc.org\/\">Pandoc<\/a> rather than the Python Markdown implementation), so I ran with it for building the Winning Slowly site, and it has worked quite well for building the site itself. It just gets built locally and deployed via <a href=\"https:\/\/pages.github.com\/\">GitHub Pages<\/a>.<\/p>\n<p>However, it does not have built-in support for generating <a href=\"https:\/\/en.wikipedia.org\/wiki\/RSS_enclosure\">podcast feeds<\/a>, even just the general case with enclosures. <a href=\"https:\/\/itunespartner.apple.com\/en\/podcasts\/overview\">iTunes podcast support<\/a> would have taken a lot of work to add.<a href=\"#fn2\" class=\"footnote-ref\" id=\"fnref2\" role=\"doc-noteref\"><sup>2<\/sup><\/a> Instead, I chose to build the RSS feed semi-manually. <em>Semi<\/em>-manually, because doing it totally manually is a recipe for making mistakes. XML is many things, but \u201ceasy to write correctly by hand\u201d is not one of them. I use <a href=\"http:\/\/reinventedsoftware.com\/feeder\/\">Feeder<\/a> to manage the feeds, and <em>it<\/em> makes sure that the enclosure and iTunes elements are set correctly.<\/p>\n<p>The biggest upside to this is that I can use Pelican without modification to how it generates feeds (apart from optionally turning them off entirely). It just <a href=\"https:\/\/github.com\/WinningSlowly\/winningslowly.org\/blob\/master\/pelicanconf.py#L99\">copies<\/a> the feed I generate to the output file during its normal build process. As suggested above, I also <em>don\u2019t<\/em> generate the other feeds which Pelican supports, as we have no need for them; we only care about the podcast feed.<\/p>\n<p>This process works equally well, with very little modification, for New Rustacean. In that case, I\u2019m generating the content by running Rust\u2019s documentation tool, <code>cargo doc<\/code><a href=\"#fn3\" class=\"footnote-ref\" id=\"fnref3\" role=\"doc-noteref\"><sup>3<\/sup><\/a> to render the \u201cAPI docs\u201d which serve as show notes. Notice the family resemblance between <a href=\"http:\/\/www.newrustacean.com\/show_notes\/\">my \u201cshow notes\u201d<\/a> and, say, the <a href=\"http:\/\/sgrif.github.io\/diesel\/diesel\/index.html\">Diesel docs<\/a>, which are both generated the same way. This is <em>not<\/em> a normal way of building a podcast website; you can hear me explain why I did it this way in <a href=\"http:\/\/www.newrustacean.com\/show_notes\/e001\/index.html\">New Rustacean e001: Document all the things!<\/a> In any case, I just take the show note-relevant parts of the documentation and put it in Feeder, generate the feed, and <a href=\"https:\/\/github.com\/chriskrycho\/newrustacean.com\/blob\/master\/Makefile#L32\">copy that as part of the build process<\/a>.<\/p>\n<p>That\u2019s it!<\/p>\n<\/section>\n<section class=\"footnotes\" role=\"doc-endnotes\">\n<hr \/>\n<ol>\n<li id=\"fn1\" role=\"doc-endnote\"><p>And, incidentally, <a href=\"http:\/\/www.sap-py.com\">Sap.py<\/a> and my <a href=\"http:\/\/v4.chriskrycho.com\/sermons.xml\">sermons<\/a> feed.<a href=\"#fnref1\" class=\"footnote-back\" role=\"doc-backlink\">\u21a9<\/a><\/p><\/li>\n<li id=\"fn2\" role=\"doc-endnote\"><p>If I stick with Pelican long-term, I might look into adding it anyway, but honestly, I don\u2019t love Pelican. The reasons have little to do with Pelican for itself, and a lot more to do with my particular and somewhat peculiar needs. That\u2019s a post for another day. In any case, I\u2019m likelier to use another generator\u2014even one I write myself!\u2014than to do the work to make Pelican do what I want.<a href=\"#fnref2\" class=\"footnote-back\" role=\"doc-backlink\">\u21a9<\/a><\/p><\/li>\n<li id=\"fn3\" role=\"doc-endnote\"><p>Technically, Rust\u2019s documentation tool is <code>rustdoc<\/code>, which <code>cargo doc<\/code> wraps around. I never actually use <code>rustdoc<\/code> directly, though.<a href=\"#fnref3\" class=\"footnote-back\" role=\"doc-backlink\">\u21a9<\/a><\/p><\/li>\n<\/ol>\n<\/section>\n","pubDate":"Sun, 28 Feb 2016 12:50:00 -0500","guid":"tag:v4.chriskrycho.com,2016-02-28:\/2016\/static-site-generators-and-podcasting.html","category":["software development","podcasting","python","rust"]},{"title":"If-expressions in Rust","link":"http:\/\/v4.chriskrycho.com\/2015\/if-expressions-in-rust.html","description":"<p>I love the fact that all <code>if<\/code> statements in Rust are expressions. It gives you a great deal of expressitivity in the language.<\/p>\n<p>Let\u2019s contrast with Python (which I love, for the record). In Python, you can do something like this:<\/p>\n<pre class=\"python\"><code>some_condition = True\nif some_condition:\n    a_value = &quot;Yeah!&quot;\nelse:\n    a_value = &quot;Oh, sads.&quot;<\/code><\/pre>\n<p>Those are <em>statements<\/em> in the body of the <code>if<\/code>\/<code>else<\/code> block; you can\u2019t assign the block itself to <code>a_value<\/code>. However, like C, C++, Java, etc., Python does provide an <em>expression<\/em>-type conditional, a ternary expression.<\/p>\n<p>So you can also do this:<\/p>\n<pre class=\"python\"><code>some_condition = True\na_value = &quot;Yeah&quot; if some_condition else &quot;Oh, sads.&quot;<\/code><\/pre>\n<p>This expression form of the <code>if<\/code> block is what all Rust <code>if<\/code> blocks are. So in Rust, the normal long form is:<\/p>\n<pre class=\"rust\"><code>let some_condition = true;\nlet a_value = if some_condition {\n    &quot;Yeah!&quot;\n}\nelse {\n    &quot;Oh, sads.&quot;\n}<\/code><\/pre>\n<p>(You could also write this with a <code>let mut a_value<\/code> and then set its value inside the conditional blocks, but that\u2019s not at all good form in Rust.)<\/p>\n<p>And of course, you can shorten that rather nicely where the expressions are brief enough:<\/p>\n<pre class=\"rust\"><code>let some_condition = true;\nlet a_value = if some_condition { &quot;Yeah!&quot; } else { &quot;Oh, sads.&quot; }<\/code><\/pre>\n<p>But this gets really nice when you have more complicated work to do in a Rust conditional. It doesn\u2019t matter how many things going on inside an <code>if<\/code> expression; it\u2019s still an expression. As such, you can also write this:<a href=\"#fn1\" class=\"footnote-ref\" id=\"fnref1\" role=\"doc-noteref\"><sup>1<\/sup><\/a><\/p>\n<pre class=\"rust\"><code>let some_condition = true;\nlet a_value = if some_condition {\n    let the_answer = 42;\n    let theme = &quot;Take my love, take my land...&quot;;\n    &quot;Yeah!&quot;  \/\/ An expression!\n}\nelse {\n    let the_question = &quot;What do you get when you multiply six by nine?&quot;;\n    let song = &quot;You can&#39;t take the sky from me!&quot;;\n    &quot;Oh, sads.&quot;  \/\/ An expression!\n}<\/code><\/pre>\n<p>Obviously this is totally contrived and silly; the point is that no matter what the internals are, <code>if<\/code> blocks are expressions, and their final expressions can be assigned like any other.<\/p>\n<hr \/>\n<p>As a note: I got here because I was originally thinking you couldn\u2019t do a one-liner like you can in Python. As shown above, that\u2019s totally false, and in fact the Rust version is much more capable than Python\u2019s, because you don\u2019t need a dedicated ternary when all <code>if<\/code> blocks are expressions. Rust used to have a C-style ternary (<code>&lt;condition&gt; ? &lt;value if true&gt; : &lt;value if false&gt;<\/code>) but it was <a href=\"https:\/\/github.com\/rust-lang\/rust\/issues\/1698\">removed<\/a> during the lead-up to the 1.0 release\u2014a decision I wholeheartedly affirm.<\/p>\n<section class=\"footnotes\" role=\"doc-endnotes\">\n<hr \/>\n<ol>\n<li id=\"fn1\" role=\"doc-endnote\"><p>Note that under normal conditions the compiler won\u2019t actually accept this because of the unused names.<a href=\"#fnref1\" class=\"footnote-back\" role=\"doc-backlink\">\u21a9<\/a><\/p><\/li>\n<\/ol>\n<\/section>\n","pubDate":"Sat, 12 Sep 2015 11:05:00 -0400","guid":"tag:v4.chriskrycho.com,2015-09-12:\/2015\/if-expressions-in-rust.html","category":["software development","programming languages","rust","python"]},{"title":"High- and Low-Level Programming Languages","link":"http:\/\/v4.chriskrycho.com\/2015\/high-and-low-level-programming-languages.html","description":"<p>It occurred to me while listening to <a href=\"https:\/\/edwinb.wordpress.com\">Edwin Brady<\/a> talk about <a href=\"http:\/\/www.idris-lang.org\">Idris<\/a> on the <a href=\"http:\/\/typetheorypodcast.com\">Type Theory Podcast<\/a>,<a href=\"#fn1\" class=\"footnote-ref\" id=\"fnref1\" role=\"doc-noteref\"><sup>1<\/sup><\/a> having just spent a few weeks starting to learn <a href=\"https:\/\/www.rust-lang.org\">Rust<\/a>: \u201clow-level\u201d has at least two meanings in software. One is whether something has manual memory management or is garbage collected, reference counted, or otherwise manages memory itself. This is what people often mean when they talk about C, C++, etc. as being \u201clow-level\u201d and languages like Python or Ruby or C\u266f being high-level.<\/p>\n<p>But then you toss in a language like <a href=\"https:\/\/www.rust-lang.org\">Rust<\/a>, and things start to get a little more complicated. Rust can do the same kind of direct memory management that makes C or C++ a good language for things like writing operating system kernels. [<a href=\"https:\/\/github.com\/torvalds\/linux\">1<\/a>,<a href=\"https:\/\/en.wikipedia.org\/wiki\/Architecture_of_Windows_NT\">2<\/a>,<a href=\"http:\/\/www.opensource.apple.com\/source\/xnu\/xnu-2782.10.72\/\">3<\/a>] But it is also memory-safe, at least in ordinary usage. Like C\u266f, you have to be explicit about any unsafe code, with the <code>unsafe<\/code> keyword on any blocks that do memory management that isn\u2019t safe. And the vast majority of Rust code <em>is<\/em> safe.<\/p>\n<p>More than that, though, Rust <em>feels<\/em> like a high-level language. It gives you higher-kinded functions, generics, traits-based composition of types, hygienic macros, and the implementation of many important parts the essentials of the language in the library. If you need to patch something, or extend something, you can do that in a straightforward way. In short, it gives you lots of good abstractions like you would expect in a high-level language.<\/p>\n<p>Rust is low-level in that you can write (and people are writing) systems-level programs in it. It is high-level in that it lets you express things in ways normally associated with languages like Haskell or OCaml or Python or Ruby. To put it simply: it\u2019s <em>low-level<\/em> in its ability to address the computer, and <em>high-level<\/em> in the abstractions it hands to a programmer. That\u2019s a powerful combination, and I hope more languages embrace it in the years to come.<\/p>\n<section class=\"footnotes\" role=\"doc-endnotes\">\n<hr \/>\n<ol>\n<li id=\"fn1\" role=\"doc-endnote\"><p>Yes, I know that\u2019s insanely nerdy. What did you expect?<a href=\"#fnref1\" class=\"footnote-back\" role=\"doc-backlink\">\u21a9<\/a><\/p><\/li>\n<\/ol>\n<\/section>\n","pubDate":"Fri, 07 Aug 2015 20:00:00 -0400","guid":"tag:v4.chriskrycho.com,2015-08-07:\/2015\/high-and-low-level-programming-languages.html","category":["programming languages","rust","python","ruby","c","cplusplus"]}]}}