1.  

    Yes, absolutely, freeze everything you can in Ruby. Just like being extremely liberal with final in Java is a good thing.

    1. 7

      Freezing shared constants is important, but I would push back against liberally sprinkling lots of Ruby code with freeze. Ruby is idiomatically a language that embraces mutability. It’s fighting an uphill, losing battle and YAGNI.

      EDIT: I have come around to this perspective after having been a proponent of final being default behavior in Java. My opinion around this isn’t too strongly held, but more a recognition of the friction of going against the grain with that approach. I do value immutability.

      1.  

        Oh, I have a fairly low bar for removing freeze from my constructors….

        ….but then I know and understand why and when I’m mutating this object, I’m not guessing.

    1. 2

      You do a decent job of using the phrase “alias keyword” however I notice the heading for that section is labeled “the alias method” (it’s not a method as you correctly state otherwise).

      I think a phrase that is potentially missing is “lexical scope”

      1. 1

        Oh sorry for the typo hehe.

        Yep, I explain what’s a lexical scope without explicitly naming it.

        I gonna update my post. Thanks for your feedback ;-)

      1. 5

        The redo keyword can be useful in the context of a loop or an enumeration.

        This may be a true statement, but I’m not sure the article provides any evidence that it’s useful.

        I’ve never written any Ruby, but this has convinced me to treat redo like python’s for...else construct.

        1. 1

          One use case is retrying a block that raised an exception, which can come in handy with transient errors like timeouts.

          1. 4

            Ruby has a special keyword just for retrying exception blocks: retry

            This article felt very similar to this appsignal blog post on the same subject.

        1. 2

          There is a public_send method that respects method visibility - to be completely honest I’m not sure how it deals with protected status, though, since protected is not typically seen in idiomatic Ruby afaict.

          I do like the perspective of looking at method dispatch in terms of sending messages, though. Decent write up!

          1. 2

            public_send does not call protected methods. And, yeah, protected rarely happens in Ruby. I consider it a mild code smell as it implies the use of inheritance.

            1. 1

              And, yeah, protected rarely happens in Ruby. I consider it a mild code smell as it implies the use of inheritance.

              I’ve always considered private to be the wrong choice, in any language, because it signals that I think I know every way anyone might ever want to extend my class. Inheritance may not always (or even often) be the right solution, but making certain extension options impossible is just going to drive future coders crazy.

              1. 2

                I use private to lower the cost for future internal refactors, and upgrades, by providing a signal that “Hey, this method is not part of the public API, I do not condone its external use, and reserve the right to change it wildly.”

                It communicates that there consciously was no consideration for what might happen if external objects began to depend on said private method. Later changes by anyone (not just the original author) can and will be free to change the private method at will: refactor, upgrade, remove entirely, and there is less to hold in your head and worry about when upgrading them later.

                However, behavior of a private method that is observable through the a public method is fair game, and test cases should exist for those. The flip side of this is that, except in some rare cases, I favor not testing private methods. Any behavior that is possible via a private method, but which cannot be exercised or observed through use of public methods, should not be considered as supported behavior on the object. That does not preclude a new public method from exposing more of the private method’s behavior later, but at that point it is part of the public interface, and should be presented and documented as such.

                As for making certain extension options impossible, at least in the context of Ruby, private does not do this.

                class PrivateGreeter
                  private
                  def greeting
                    "Hello."
                  end
                end
                
                class PublicGreeter < PrivateGreeter
                  def speak
                    greeting
                  end
                end
                
                irb> PrivateGreeter.new.greeting
                # => NoMethodError: private method `greeting' called for #<PrivateGreeter>
                irb> PublicGreeter.new.speak
                # => "Hello."
                

                You can even give it the same name as the parent class’ private method if you really, truly need to let external objects utilize the method as part of the subclass’ public API with the exact same name:

                class PublicGreeter < PrivateGreeter
                  def greeting
                    super
                  end
                end
                
                irb> PrivateGreeter.new.greeting
                # => NoMethodError: private method `greeting' called for #<PrivateGreeter>
                irb> PublicGreeter.new.greeting
                # => "Hello."
                

                Since an inherited class can make use of its parent class’ private method, the question then becomes: should it? If we have a stipulation that the parent class reserves the right to refactor its private methods or change them wildly, should we rely on a parent class’ private method?

                I think the answer differs between application code and library code. If the parent class comes from a library, or some internal, but still cross-domain, utility code, I would not want to rely on the existence, the arity, or the behavior of a private method. If the behavior is so critical, I would rather capture the behavior permanently as part of the subclass by copying the code itself over to the subclass (or not use inheritance at all, but I would still definitely copy the code). Everything I have seen makes me agree that duplication is far cheaper than the wrong abstraction.

                In the case of application code, it is more acceptable to rely on a parent class’ internals. I still would fight the urge, but it can be expected that the author modifying the subclass and parent class has access and authority to work on both in order to get their job done, that the tests for both classes live in the same suite, and other niceties that make maintaining that dependency across time situation more tenable.

            2. 1

              Thanks for your great feedback ! That’s motivates me to do even more :-)

            1. 3

              I don’t write a lot, but I’m trying to continue writing at least a little:

              http://www.soulcutter.com

              Yes, I know, I need to get https goin

              1. 5

                I am mildly dismayed by the amount of active participation it takes to enhance browser privacy. I’m not suggesting that all these extensions should be baked-in to Firefox, it’s more commentary on how out-of-control privacy things have become on the web today.

                1. 2

                  Unfortunately, all of the browser developers (Google, Mozilla, Apple, and Microsoft) have vested interest in not improving privacy by default.

                  There’s just too much money to be made off the people who don’t know any better.

                1. 12

                  A realization I recently had:

                  Why don’t we abstract away all display affordances from a piece of code’s position in a file? That is, the editor reads the file, parses its AST, and displays it according to the programmer’s preference (e.g., elastic tabstops, elm-like comma-leading lists, newline/no-newline before opening braces, etc). And prior to save, the editor simply runs it through an uncustomized prettier first.

                  There are a million and one ways to view XML data without actually reading/writing pure XML. Why not do that with code as well?

                  1. 4

                    This idea is floating around the interwebz for a long time. I recall it being stated almost verbatim on Reddit, HN, probably on /.

                    1. 6

                      And once you take it a step further, it’s clear that it shouldn’t be in a text file in the first place. Code just isn’t text. If you store it as a tree or a graph in some sort of database, it becomes possible to interact with it in much more powerful ways (including displaying it any way you like). We’ve been hobbled by equating display representation with storage format.

                      1. 7

                        This talk touches on this issue, along with some related ones and HCI in general: Bret Victor: The Future of Programming

                        1. 2

                          God, I have been trying to recall the name of this talk for ages! Thank you so much, it is a great recommendation

                        2. 5

                          Text is great when (not if) your more complicated tools fail or do something you can’t tolerate and you need to use tools which don’t Respect The Intent of designers who, for whatever reason, don’t respect your intent or workflow. Sometimes, solving a problem means working around a breakage, whether or not that breakage is intentional on someone else’s part.

                          Besides, we just (like, last fifteen or so years) got text to the point where it’s largely compatible. Would be a shame to throw that away in favor of some new AST-database-thing which only exists on a few platforms.

                          1. 1

                            I’m not sure I get your point about about intent. Isn’t the same already true of, say, compilers? There are compiler bugs that we have to work around, there are programs that seem logical to us but the compiler won’t accept, and so on. Still, everybody seems to be mostly happy to file a compiler bug or a feature request, and live with a workaround for the present. Seems like it works well enough in practice.

                            I understand your concern about introducing a new format but it sounds like a case of worse-is-better. Sure, we get a lot of convenience from the ubiquity of text, but it would nevertheless be sad if we were stuck with it for the next two centuries.

                            1. 1

                              With compilers, there are multiple of them for any given language, if the language is important enough, and you can feed the same source into all of them, assuming that source is text.

                              1. 2

                                I’ve never seen anyone casually swap out the compiler for production code. Also, for the longest time, if you wrote C++ for Windows, you pretty much had to use the Microsoft compiler. I’m sure that there are many embedded platforms with a single compiler.

                                If there’s a bug in the compiler, in most casss you work around it, then patiently wait for a fix from the vendor.

                                So that’s hardly a valid counterpoint.

                                1. 1

                                  Re: swapping out compiler for production code: most if not all cross-platform C++ libraries can be compiled on at least llvm, gcc and msvc.

                                  1. 1

                                    Yes, I’m aware of that, but what does it have to do with anything I said?

                                    EDIT: Hey, I went to Canterbury :)

                                    1. 1

                                      “I’ve never seen anyone casually swap out the compiler for production code” sounded like you were saying people didn’t tend to compile the same production code on multiple compilers, which of course anyone that compiles on windows and non-windows does. Sorry if I misinterpreted your comment!

                                      My first comment is in response to another Kiwi. Small world. Pretty cool.

                          2. 1

                            This, this, a thousand times this. Text is a good user-interface for code (for now). But it’s a terrible storage and interchange format. Every tool needs its own parser, and each one is slightly different, leaving begging the amount of cpu and programmer time we waste going from text<->ast<->text.

                            1. 2

                              Yeah, it’s obviously wasteful and limiting. Why do you think we are still stuck with text? Is it just sheer inertia and incrementalism, or does text really offer advantages that are challenging to recreate with other formats?

                              1. 7

                                The text editor I use can handle any computer language you can throw at it. It doesn’t matter if it’s BASIC, C, BCPL, C++, SQL, Prolog, Fortran 77, Pascal, x86 Assembler, Forth, Lisp, JavaScript, Java, Lua, Make, Hope, Go, Swift, Objective-C, Rexx, Ruby, XSLT, HTML, Perl, TCL, Clojure, 6502 Assembler, 68000 Assembler, COBOL, Coffee, Erlang, Haskell, Ocaml, ML, 6809 Assembler, PostScript, Scala, Brainfuck, or even Whitespace. [1]

                                Meanwhile, the last time I tried an IDE (last year I think) it crashed hard on a simple C program I attempted to load into it. It was valid C code [2]. That just reinforced my notion that we aren’t anywhere close to getting away from text.

                                [1] APL is an issue, but only because I can’t type the character set on my keyboard.

                                [2] But NOT C++, which of course, everybody uses, right?

                                1. 0

                                  To your point about text editors working with any language, I think this is like arguing that the only tool required by a carpenter is a single large screwdriver: you can use it as a hammer, as a chisel, as a knife (if sharpened), as a wedge, as a nail puller, and so on. Just apply sufficient effort and ingenuity! Does that sound like an optimal solution?

                                  My preference is for powerful specialised tools rather than a single thing that can be kind of sort of applied to a task.

                                  Or, to approach from the opposite direction, would you say that a CAD application or Blender are bad tools because they only work with a limited number of formats? If only they also allowed you to edit JPEGs and PDFs, they would be so much better!

                                  To your point about IDEs: I think that might even support my argument. Parsing of freeform text is apparently sufficiently hard that we’re still getting issues like the one you saw.

                                  1. 9

                                    I use other tools besides the text editor—I use version control, compilers, linkers, debuggers, and a whole litany of Unix tools (grep, sed, awk, sort, etc). The thing I want to point out is that as long as the source code is in ASCII (or UTF-8), I can edit it. I can study it. I might not be able to compile it (because I lack the INRAC compiler but I can still view the code). How does one “view” Smalltalk code when one doesn’t have Smalltalk? Or Visual Basic? Last I hear, Microsoft wasn’t giving out the format for Visual Basic programs (and good luck even finding the format for VB from the late 90s).

                                    The other issue I have with IDEs (and I will come out and say I have a bias against the things because I’ve never had one that worked for me for any length of time without crashing, and I’ve tried quite a few over 30 years) is that you have one IDE for C++, and one for Java, and one for Pascal, and one for Assembly [1] and one for Lua and one for Python and man … that’s just too many damn environments to deal with [2]. Maybe there are IDEs now that can work with more than one language [3] but again, I’ve yet to find one that works.

                                    I have nothing against specialized tools like AutoCAD or Blender or PhotoShop or even Deluxe Paint, as long as there is a way to extract the data when the tool (or the company) is no longer around. Photo Shop and Deluxe Paint work with defined formats that other tools can understand. I think Blender works with several formats, but I am not sure about AutoCAD (never having used it).

                                    So, why hasn’t anyone stored and manipulated ASTs? I keep hearing cries that we should do it, but yet, no one has yet done it … I wonder if it’s harder than you even imagine …

                                    Edited to add: Also, I’m a language maven, not a tool maven. It sounds like you are a tool maven. That colors our perspectives.

                                    [1] Yes, I’ve come across several of those. Never understood the appeal …

                                    [2] For work, I have to deal with C, C++, Lua, Make and Perl.

                                    [3] Yeah, the last one that claimed C/C++ worked out so well for me.

                                    1. 1

                                      For your first concern about the long term accessibility of the code, you’ve already pointed out the solution: a defined open format.

                                      Regarding IDEs: I’m not actually talking about IDEs; I’m talking about an editor that works with something other than text. Debugging, running the code, profiling etc. are different concerns and they can be handled separately (although again, the input would be something other than text). I suppose it would have some aspects of an IDE because you’d be manipulating the whole code base rather than individual files.

                                      Regarding the language maven post: I enjoyed reading it a few years ago (and in practice, I’ve always ended up in the language camp as an early adopter). It was written 14 years ago, and I think the situation is different now. People have come to expect tooling, and it’s much easier to provide it in the form of editor/IDE plugins. Since language creators already have to do a huge amount of work to make programs in their languages executable in some form, I don’t think it would be an obstacle if the price of admission also included dealing with the storage format and representation.

                                      To your point about lack of implementations: don’t Smalltalk and derivatives such as Pharo qualify? I don’t know if they store ASTs but at least they don’t store text. I think they demonstrate that it’s at least technically possible to get away from text, so the lack of mainstream adoption might be caused by non-technical reasons like being in a local maximum in terms of tools.

                                      The problem, as always, is that there is such a huge number of tools already built around text that it’s very difficult to move to something else, even if the post-transition state of affairs would be much better.

                                      1. 1

                                        Text editors are language agnostic.

                                        I’m trying to conceive of an “editor” that works with something other than text. Say an AST. Okay, but in Pascal, you have to declare variables at the top of each scope; you can declare variables anywhere in C++. In Lua, you can just use a variable, no declaration required. LISP, Lua and JavaScript allow anonymous functions; only the latest versions of C++ and Java allow anonymous functions, but they they’re restricted in that you can’t create closures, since C++ and Java have no concept of closures. C++ has exceptions, Java has two types of exceptions, C doesn’t; Lua kind of has exceptions but not really. An “AST editor” would have to somehow know that is and isn’t allowed per language, so if I’m editing C++ and write an anonymous function, I don’t reference variables outside the scope of said function, but that it can for Lua.

                                        Okay, so we step away from AST—what other format do you see as being better than text?

                                        1. 1

                                          I don’t think it could be language agnostic - it would defeat the purpose as it wouldn’t be any more powerful than existing editors. However, I think it could offer largely the same UI, for similar languages at least.

                                          1. 1

                                            And that is my problem with it. As stated, I use C, C++ [1], Lua, Make and a bit of Perl. That’s at least what? Three different “editors” (C/C++, Lua/Perl (maybe), Make). No thank you, I’ll stick with a tool that can work with any language.

                                            [1] Sparingly and where we have no choice; no one on my team actually enjoys it.

                                          2. 1

                                            Personally, I’m not saying you should need to give up your editor of choice. Text is a good (enough for now) UI for coding. But it’s a terrible format to build tools on. If the current state of the code lived in some sort of event-based graph database for example, your changes could trigger not only your incremental compiler, but source analysis (only on what’s new), it could also maintain a semantic changelog for version control, trigger code-generation (again, only what’s new).

                                            There’s a million things that are currently “too hard” which would cease to be too hard if we had a live model of the code as various graphs (not just the ast, but call graphs, inheritance graphs, you-name-it) that we could subscribe to, or even write purely-functional consumers that are triggered only on changes.

                                  2. 4

                                    Inertia, arrogance, worse-is-better; Working systems being trapped behind closed doors at big companies; Hackers taking their language / editor / process on as part of their identity that needs to be defended with religious zeal; The complete destruction of dev tools as a viable business model; Methodologies-of-the-week…. The causes are numerous and varied, and the result is software dev is being hamstrung and we’re all wasting countless hours and dollars doing things computers should be doing for us.

                                    1. 2

                                      I think that part of the issue is that we haven’t seen good structured editor support outside of Haskell and some Lisps.

                                      Having a principled foundation for structured editor + a critical mass by having it work for a language like Javascript/Ruby, would go a long way to making this concept more mainstream. After which we could say “provide a grammar for favorite language X and get structured editor support!”. This then becomes “everything is structured at all levels!”

                                      1. 3

                                        I think it’s possible that this only works for a subset of languages.

                                        Structured editing is good in that it operates at a higher level than characters, but ultimately it’s still a text editing tool, isn’t it? For example, I think it should be trivial to pull up a list of (editable) definitions for all the functions in a project that call a given function, or to sort function and type definitions in different ways, or to substitute function calls in a function with the bodies of those functions to a given depth (as opposed to switching between different views to see what those functions do). I don’t think structured editing can help with tasks like that.

                                        There are also ideas like Luna, have you seen it? I’m not convinced by the visual representation (it’s useful in some situations but I’m not sure it’s generally effective), but the interesting thing is they provide both a textual and a visual representation of the code.

                                    2. 1

                                      Python has a standard library module for parsing Python code into an AST and modifying the AST, but I don’t know of any Python tools that actually use it. I’m sure some of them do, though.

                                    3. 1

                                      Smalltalk. The word you’re looking for is Smalltalk. ;)

                                      1. 2

                                        Lisp, in fact. Smalltalk lives in an image, Lisp lives in the real world. ;)

                                        Besides, Lisp already is the AST. Smalltalk has too much sugar, which is a pain in the AST.

                                        1. 1

                                          Possibly, but I’m only talking about a single aspect of it: being able to analyse and manipulate the code in more powerful ways than afforded by plain text. I think that’s equally possible for FP languages.

                                      2. 1

                                        Ultimately I think this is the only teneble solution. I feel I must be in the minority in having an extreme dislike of columnar-style code, and what I call “white space cliffs” where a column dictates a sudden huge increase in whitespace. But I realize how much it comes down to personal aesthetics, so I wish we could all just coexist :)

                                        1. 1

                                          Yeah, I’ve been messing around with similar ideas, see https://nick.zoic.org/art/waste-web-abstract-syntax-tree-editor/ although it’s only vapourware so far because things got busy …

                                          1. 1

                                            Many editors already do this to some extent. They just render 4-space tabs as whatever the user asks for. Everything after the indent, though, is assumed to be spaced appropriately (which seems right, anyway?)

                                            1. 1

                                              You can’t convert to elastic-tabstop style from that, and without heavy language-grammar knowledge you can’t do this for 4-space “tabs” generally.

                                              Every editor ever supports this for traditional indent style, though: http://intellindent.info/seriously/

                                              1. 1

                                                To be clear, you can absolutely render a file that doesn’t have elastic tabstops as if it did. The way a file is rendered has nothing to do with the actual text in the file.

                                                It’s like you’re suggesting that you can’t render a file containing a ton of numbers as a 3D scene in a game engine. That would be just wrong.

                                                Regardless, my point is specifically that this elastic tabstops thing is not necessary and hurts code readability more than it helps.

                                                The pefantics of clarifying between tabs and tabstops is a silly thing as well. Context gives more than enough information to know which one is being talked about.

                                                It sounds like this concept is creating more problems than it solves, and is causing your editor to solve problems that only exist in the seveloper’s imagination. It’s not “KISS” at all, quite the opposite.

                                            2. 1

                                              Because presentation isn’t just a function of the AST. Indentation usually is, but alignment can be visually useful for all kinds of reasons.

                                            1. 8

                                              I’ve been happy-enough with LastPass - I can’t point to any reason beyond inertia, so really what I’m curious about in this thread: are there any significant differentiators that could sway a person to switch?

                                              1. 7

                                                A big reason for me would be moving away from proprietary stuff to secure my passwords

                                                1. 5

                                                  To my knowledge at least by staying mainstream there’s a team of individuals working on the product. Ive used LastPass for years, and while there have been issues in the past … There is a large userbase and community scrutinizing it.

                                                  Going the self hosted route negates alot of the large community, and trail by fire already accrued by legacy solutions like LastPass.

                                                  They also provide an export mechanism …

                                                2. 4

                                                  I’ve stuck with LastPass for a while. AFAIK, no security issues that I’ve judged to be significant. I appreciate that, compared to the other solutions that I know of, it seems to be widely compatible and simple to use on all platforms.

                                                  Only minor beef that I have is that the browser plugins, or at least the Chrome one, seems to have gotten slower and a little bit buggier over time instead of better and faster.

                                                  1. 1

                                                    I use LastPass, but am not happy with it, as in the past, it had some pretty serious security issues:

                                                    1. https://www.martinvigo.com/even-the-lastpass-will-be-stolen-deal-with-it/. They fixed it promptly, of course, but it worries me.
                                                    2. https://news.ycombinator.com/item?id=8031720#8032186
                                                    3. https://twitter.com/tqbf/status/836619941805764609
                                                    4. https://twitter.com/taviso/status/843965519371812864

                                                    I would switch to 1Password, but it does not have linux support (edit: it has a browser extension for linux, which is suboptimal, but probably better than Lastpass). I’ve almost talked myself into switching to Keepass, but I’ll have to find out how trustworthy the iOS version is.

                                                  1. 3

                                                    My personal experience filing a complaint against my ISP for data caps was that they forwarded the complaint to my ISP, who responded to me with a generic letter about how their policies ensure providing the best experience for their customers, and the complaint was considered addressed/closed. It was a complete waste of time and at no point did I get the impression that anybody at the FCC gave two shits about it, and the entire process seemed oriented around providing the ISP a chance to send a generic response. Disenfranchising. I got nothing but aggravation from the experience and do not consider it as any form of recourse or being heard by anybody.

                                                    1. 2

                                                      Great post - I admit to being a bit curious to see those rspec macros too, even if it’s not a general approach.

                                                      1. 5

                                                        I don’t know about macros; but, I often generate tests from data in rspec. I too am curious what the macros bring to the table.

                                                        I found this rspec truth table DSL too. It has a nice syntax…

                                                        1. 2

                                                          I really wish I could share them, but it was at an old job and I don’t have the source code :(

                                                          1. 1

                                                            I don’t know about Rust. The matching in F# allows coding up sophisticated match situations. The compiler will tell you if you have left out a case. My favorite example is balancing a Red/Black Tree. This would be many lines of hard to understand imperative code:

                                                            type a t =

                                                            | Node of color * a * a t * a t 
                                                            
                                                            | Leaf
                                                            

                                                            let balance = function

                                                            | Black, z, Node (Red, y, Node (Red, x, a, b), c), d
                                                            
                                                            | Black, z, Node (Red, x, a, Node (Red, y, b, c)), d
                                                            
                                                            | Black, x, a, Node (Red, z, Node (Red, y, b, c), d)
                                                            
                                                            | Black, x, a, Node (Red, y, b, Node (Red, z, c, d)) ->
                                                            
                                                            	Node (Red, y, Node (Black, x, a, b), Node (Black, z, c, d))
                                                            | x -> 
                                                            	Node
                                                            
                                                          1. 11

                                                            I’ve read a number of posts by Uncle Bob that I’ve disliked - I don’t think that programmers are a special class of people who are duty-bound to take an oath to uphold the honor of the profession, as opposed to just people with a particular skill/interest in manipulating computer systems; and he’s said things about unit testing vis a vis static typing that I thought were wrong. In light of this though:

                                                            Only when he writes something that I strongly disagree with, does the hunch about Clean Code became clear. The > last days on Twitter we watched Uncle Bob implicitly decry the violation of Godwin’s law rather than the internment > of thousand children under conditions that Amnesty International compare with torture. In the following days, Uncle > Bob fought back against his critics also stressing that he thinks the situation is horrible, “but…” not as important as > “unhonorably” comparing others to Nazis. I think his priorities are horribly wrong. I responded “In light of @unclebobmartin’s recent tweets, ideas like Clean Code have started creating a bad taste in my mouth. Let’s just say “code”, eh? I’m officially instituting “dirty code Monday’s” to remember to question dogma, tribalism and things- before-people mentality.” Bob asked me to explain “why you decided to lead a boycott against the concept of Clean > Code”. Thus this blog post.

                                                            I think it’s pretty clear that this blog post is in large part motivated by a political disagreement rooted in very contemporary (as in, the past couple of weeks) American national politics, and that leaves a very bad taste in my mouth.

                                                            1. 9

                                                              I didn’t quite get this link either, though there are people who will reject all ideas that come from a person because of their disagreement with one of them. But, in this case, it seems like the author has been becoming disillusioned with Clean Code for a while.

                                                              From other parts of the post, it seemed like the root problem the author has experienced is probably one of battling ideologies

                                                              Some of the most unpleasant experience in my professional life have been due to disagreements of the Clean way to write some piece of Code. I know people that I respect professionally that could have been good friends if one of us hadn’t insisted on purity of code in some situation or another.

                                                              and possibly burn-out

                                                              I often leave the office 1-2 hours later than my co-workers after polishing some piece of ultimately meaningless code. This is time I don’t spend with my family. Because I’ve learned to care about Clean Code.

                                                              But they seem to have reached the conclusion that it’s not worth caring about code quality, which to me is throwing the baby out with the bathwater.

                                                              As I’ve grown older, I learned to stop getting upset about “Unclean” Code. In any real world code base there will be an uncountable number of unfortunate quirks, odd and ends. Things are the way they are because they got that way. People did what they did because of reasons. Those reasons are valid, whether it was because the surrounding needs changed, because the developer had insufficient experience, because they wanted to go home to their family instead of sitting late in the office or if they just had a difference in opinion on what’s good code.

                                                              I’d agree that it’s probably not good (or productive) to get upset about ‘“Unclean” Code’, but the idea that everything is the way it is “because of reasons. Those reasons are valid”, is far too reductive for me, and just feels like giving up.

                                                              1. 6

                                                                Relativism of code quality seems to be en vogue nowadays. I’ve seen extremes of it, up to the ridiculous “there is no bad code, just bad circumstances forcing bad code to happen.” People are projecting their nature/nurture beliefs into software dev. Also, it feels more like pushback to the dogmatism of clean code that went around for awhile. But like many “anti-“ movements, it doesn’t offer much guidance beyond “don’t do that thing!” Which I guess makes it a great tweet to post?

                                                                So, I’m pretty bummed he just arrives at a relativistic argument and declares himself enlightened. It is quite possible to write clean code and go home at 5, or even earlier. Perhaps one can write a few tests instead of reading hot takes on Twitter/HN?

                                                                Code quality is almost entirely up to developers. Don’t give up on it because it can be a demanding task.

                                                                1. 11

                                                                  IMO there’s a difference between “code quality” and “clean code”. “Code quality” is a general term for code that has some desirable property, usually legibility, little tech debt, and simplicity. “Clean code” is a specific, idiosyncratic style of writing code that purports to be objectively better.

                                                                  See for example Martin’s extract till you drop, where he replaces a 10 line method with a 4 line method… and six additional helper methods.

                                                                  1. 2

                                                                    That reminds me of my controversial post about using local variables rather than extracting methods. There are some who insist that the method explosion caused by extracting everything is desirable - a lot of times I think YAGNI.

                                                                  2. 7

                                                                    Relativism of code quality seems to be en vogue nowadays. I’ve seen extremes of it, up to the ridiculous “there is no bad code, just bad circumstances forcing bad code to happen.”

                                                                    I think it starts out from Chesterton’s Fence, which I see trotted out fairly regularly, but then it is carried too far. It goes from “make sure you understand why the fence/code was put there before you remove/change it” to “whatever reason the code/fence was put there must have been a good one”, which is different. It also misses the difference between why the fence/code was put there, and the quality of the fence/code itself.

                                                                2. 3

                                                                  It’s true that this situation in which he tells us that the separation of parents from their children while they face summary judgement without due process is not all that bad after all could just be an isolated incident, but it isn’t. He’s also the person who says that unless you write software his way you are unprofessional. The person who said that James Damore had a good point and maybe we should have listened to him instead of letting him get fired. The person who said that it’s fine to call all professionals “men”. So maybe this was, for OP, the straw that broke the camel’s back.

                                                                  I have been asking for years that we get better heroes in our trade, I’m happy to no longer be alone in that.

                                                                1. 1

                                                                  TBH, I feel that’s a pretty ugly workaround to avoid fixing the real problems of a slow exception mechanism and an inconsistent library interface.

                                                                  1. 1

                                                                    If you read the issue tracker, the performance bit is really secondary to avoiding debug output by jumping through hoops. I think the author took the wrong part to highlight in their write up.

                                                                    Exception performance is not the problem to be solved here - exceptions are intended to be, well, exceptional and using them for flow control rather than error handling is a bit of a smell.

                                                                    As far as the inconsistent interface, conversion functions have consistency and aren’t intended to mirror implicit casting methods. It’s been a while since I’ve read Confident Ruby, but as I recall it covers the topic really well. Let’s also say that hypothetically you were to resolve that inconsistency - that would be a breaking change which is in all likelihood not worth the cost. This change is backwards compatible, solves the problem of jumping through hoops to avoid debug output, and is consistent in the conversion function interface.

                                                                    Now, whether this is something a lot of Rubyists will need to know or care about… probably not. I’d relegate this to the realm of Ruby trivia for a very select set of problems. It’s a good change, though.

                                                                  1. 12

                                                                    I think the title buries the lede (but was clickbaity enough for me to be interested). As stated in the article:

                                                                    The point of the comparison isn’t that Elastic Transcoder is a ripoff, it’s that Lambda can often result in significant cost savings if you have a well-defined use case that’s compatible with the limitations that Lambda imposes.

                                                                    The tip about using Exodus alone was really helpful - I learned a new thing that could be super-useful where I previously would have gone down the rabbit hole of compiling native binaries on the Lambda AMI. Good stuff!

                                                                    1. 2

                                                                      as a non ruby programmer I wonder: What do you all need infinite ranges for that you need a special syntax for it. I think I never had a need for that. So I wonder, what are they used for?

                                                                      1. 2

                                                                        How about a game loop that keeps track of ticks?

                                                                        As a Ruby programmer I have definitely written infinite ranges a handful of times - it does come up, though it’s not common.

                                                                        1. 1

                                                                          there are examples in the blog post, but (also as a non ruby programmer) I don’t find any of them particularly compelling

                                                                          1. 1

                                                                            I am a Ruby programmer, and I’m also not sure what people need infinite ranges for so often.

                                                                            1. 1

                                                                              I use them, but that’s probably me porting Hasellisms to Ruby more than a common Rubyism. Things like: (0..1.0/0).zip(array)

                                                                              1. 1

                                                                                Yeah it’s probably more Ruby-ist to use each_with_index for that, but it’s interesting that that works.

                                                                          1. 3

                                                                            If you want to avoid metaprogramming then I recommend setting up a snippet in your editor that expands to a memoized method. For example, when I type memo<TAB> (I use UltiSnips) then the following appears:

                                                                            def name
                                                                              @name ||= value
                                                                            end
                                                                            

                                                                            UltiSnips keeps name in sync both in the method name and attribute name. Pressing <TAB> one more time takes me to value. You can of course do the same for the more bullet-proof approach described in the article.

                                                                            1. 2

                                                                              That’s a good point. I do use RubyMine live templates, and there’s a way to do something like that in most editors.

                                                                            1. 3

                                                                              Another anti-pattern is making the Controller instance manage the Serializer. Ideally, the Controller just returns an object, and any need to transform that object to a specific format is handled decoratively or via DI. Transformations don’t belong in business logic.

                                                                              1. 4

                                                                                I somewhat regret using a controller as the example, because this is applicable to any Ruby object. Its so easy to get into controller analysis rather than my main gist.

                                                                                1. 1

                                                                                  My rule still applies- controller or not, they should just return the structure that makes sense to them. If it doesn’t make sense to the consumer, put a layer of indirection between them. As much as I am wary of indirection, objects should do what makes sense to the object.

                                                                              1. 6

                                                                                I’ve seen a similar thing with tests written in rspec where lets are exclusively used in place of local variables. Any thoughts on how to strike the balance there?

                                                                                1. 5

                                                                                  YES! This advice completely applies to let variables in RSpec tests too. A let is a memoized method definition in my book. I am happy to recommend using more local variables over let variables in tests.

                                                                                1. 3

                                                                                  I am not satisfied by this argument.

                                                                                  I don’t think unseating rails is easy, and the author’s prediction may very well come true, I don’t agree with the reasoning for why. Inertia is powerful, brainshare is hard to overcome.

                                                                                  Dumping any semblance of what folks call “magic” as a discriminator isn’t what is going to win folks over. I can’t say for certain what will, except that having unique and clear advantages will help. It’s about timing, luck, effort, money, and ideas.

                                                                                  1. 3

                                                                                    Maybe this will sound ridiculous, but is there a good reason to not allow wild-west tagging? I get that this community has a curated bend to it, but what would the drawbacks be of opening that up?

                                                                                    1. 10

                                                                                      I think the idea is that if it doesn’t fit an existing tag the post is off-topic. Tag creation references posts that I guess we’re agreeing as a community were on-topic but had to be shoehorned in to existing tags.

                                                                                      I’ve at least on one or two occasions ran in to a story that I couldn’t really fit in a tag so skipped submitting. Overall I like the approach.

                                                                                      1. 2

                                                                                        Ah yeah, that’s right. Welp, it was a crackpot idea after all :) Thanks for reminding me of the signal provided by tags, it’s surely useful.

                                                                                    1. 5

                                                                                      I’m working on a Ruby talk called “Metaprogramming with super powers” that I’m giving at the Indianapolis Ruby Brigade meetup on Valentine’s Day. Sadly it was rejected from RailsConf, so I’m 0/4 on my conference talk submissions - just gonna keep working the meetup circuit.

                                                                                      Also working on some finishing touches on an Instrumentation gem based loosely on my blog post on instrumenting Ruby methods. I released 1.0 last Friday, but there’s still some improvements I want to make. It’s not currently open source, but may be suitable to release at some point.