News for hackers. Stuff that matters.
Re:Upgrading GitHub from Rails 3.2 to 5.2 by majewsky on Friday September 28, 2018 @01:00PM (#18094928)
> Ruby is one of the most dangerous dynamic languages to refactor

A thousand times this. It's so much easier to do breaking changes and refactors in a language that's supporting you, instead of working against you.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by jb3689 on Friday September 28, 2018 @02:19PM (#18095682)
I disagree with this slightly. I've been using Ruby for a long, long time and Ruby does give you the tools to refactor safely - few people actually know how to use them though and there aren't very many high-level tools aimed at doing safe large-scale refactoring. In Ruby you can trace calls and do very powerful introspection which you can verify to make sure things like delegation happened properly

It also doesn't help when most codebases are using ActiveRecord or something in every complex class and wind up increasing the interface width and ancestor depth of their code significantly. The point is - I think the language does a pretty good job supporting the developers, but there are a lot of bad practices that are still in use and recommended. Can't fault the language because people are writing shit code

Re:Upgrading GitHub from Rails 3.2 to 5.2 by sorbits on Friday September 28, 2018 @03:06PM (#18096136)
What tools are you talking about?

The “problem” with ruby is that you basically don’t know if code is valid unless you execute it, whereas a statically typed language will enforce a lot of things during compilation and simply not allow the program to compile, if API is used in the wrong way, this could be calling private functions, referencing undefined symbols (simple typos), wrong number of arguments, passing a string where integer is expected, etc.

Additionally access control is limited in Ruby, which makes it difficult to release a library and have the language enforce that people do not rely on things which are implementation details subject to change.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by jb3689 on Friday September 28, 2018 @04:20PM (#18096711)
You're right - all of those things are possible. What I'm arguing is that given you have a reasonably good test suite and are aware of what patterns to are dangerous, you can refactor fairly confidently with the tools given

For example, it's possible to fetch a class's entire interface before and after a refactor and validate it is the same. It's possible to dynamically wrap every method you're refactoring track them and type check them. And if you extend that idea, now you can output this data to files and perform static analysis. Sure, it all relies on you having some safe execution context to get this information but Ruby probably has the best testing tools of any language and many projects have great test coverage

For library owners, I agree with you - there's no hope. But for application developers maintaining their monoliths with nothing depending on them there's a lot you can do to ensure safe refactoring

Re:Upgrading GitHub from Rails 3.2 to 5.2 by cknoxrun on Friday September 28, 2018 @01:32PM (#18095226)
Dynamic language or not, having good test coverage will be your biggest support.
Re:Upgrading GitHub from Rails 3.2 to 5.2 by weberc2 on Friday September 28, 2018 @02:21PM (#18095692)
It's definitely important, but we (Python shop) have "good" (85%) test coverage and we still see 500s in prod every day because of things a type checker could trivially catch. And this is just in the course of normal operation; this isn't even a migration. Having extensive experience with both Go and Python, I would conservatively estimate that Go requires ~30% fewer tests than untyped Python for the same confidence. That's more than 30% time savings; not only are you not writing 30% of the tests, but that's 30% fewer tests to have to maintain. Of course these aren't the only considerations--for certain tasks Python may be faster to develop with (although I think people forget about things like deployment, tooling, dependency management, performance requirements, etc when they make their estimations).
Re:Upgrading GitHub from Rails 3.2 to 5.2 by MattHeard on Friday September 28, 2018 @02:46PM (#18095929)
Line coverage is not test coverage.

Having a test execute every line in your application doesn't mean your application is _covered_ or _tested_.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by weberc2 on Friday September 28, 2018 @11:29PM (#18098566)
Yes, we all know the metric is easily gamed but no one at our org is trying to game the metric. We are paid to build a product, not to boost the metric.
Re:Upgrading GitHub from Rails 3.2 to 5.2 by kbp on Sunday September 30, 2018 @03:33PM (#18107912)
It's not about gaming the metric, it's just that the metric doesn't mean very much in the first place. Running a coverage tool during tests won't show you edge cases you forgot to handle in the code under test, it will show you code that's not tested at all. That can sometimes be useful for pointing out blind spots, but you shouldn't derive any confidence in the tests from a high coverage score, even if the people who worked on the project had the best intentions.

Coverage tools could only measure quality of a test suite if you're assuming that either the code is perfect or that the existing tests cover (logically) everything about what they test. Without either of those guarantees, it doesn't tell you anything very meaningful, as you discovered.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by weberc2 on Monday October 01, 2018 @09:02AM (#18112165)
The metric is meaningful; I think you’re misinterpreting it. To your point, 100% coverage doesn’t mean you’ve eliminated all bugs, but it does mean that your code base almost certainly has a lower bug yield that the code base with 50% coverage (assuming no one has games the metric).

If you really think that the metric is meaningless and useless for deriving confidence, then you are necessarily asserting that code bases with 100% coverage have indistinguishable bug yields compared to those with 50%, 5%, or even 0% coverage. A claim like this is too extraordinary to be believed without considerable evidence.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by kbp on Wednesday October 03, 2018 @01:08PM (#18132358)
I guess it's useful for deriving a baseline level of confidence, like a low coverage score is a red flag, and an increasing coverage score probably corresponds to increasing test coverage, but my issue is that 100% coverage doesn't mean anything about the correctness of the code in absolute terms (unless 'gaming the metric' includes not thinking of every edge case, ie, that we're assuming the existing test suite is perfect). If you're working on a poorly tested codebase, it's a useful relative metric of your progress in testing what already exists, but unless you're assuming the code is already correct, that doesn't mean anything more than that. If you wanted to derive, say, the confidence that you won't see 500's daily in production from a metric, then line coverage isn't an effective one to use for that; the tests you write that give you that kind of confidence don't really help your coverage score. The parts of the codebase that are in the most urgent need of tests for getting that kind of confidence in places will most of the time be ones that already have good coverage; think of how TDD works, even if you're not doing TDD.

I could agree that a high coverage score is a prerequisite for having confidence that your test suite is comprehensive (in general), but that's such a low bar, it's like saying a full bath is a prerequisite for a nice house, just knowing that shouldn't do much to convince you it's a mansion.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by jb3689 on Friday September 28, 2018 @02:36PM (#18095834)
I noticed something similar with Elixir with regards to the number of tests we needed thanks to the compiler, but it also has late binding (albeit it is statically typed). A "best of both worlds" exists out there
Re:Upgrading GitHub from Rails 3.2 to 5.2 by ezekg on Friday September 28, 2018 @04:42PM (#18096883)
Integration tests are your friend. ;)
Re:Upgrading GitHub from Rails 3.2 to 5.2 by thefounder on Friday September 28, 2018 @01:19PM (#18095103)
What dynamic language is easy to refactor? I remember the "good" old PHP days and I can't say it was easy either.
Re:Upgrading GitHub from Rails 3.2 to 5.2 by coder543 on Friday September 28, 2018 @01:49PM (#18095385)
TypeScript and Python 3 support gradual typing, so code can be optionally annotated with types. This makes refactoring easier, while still benefitting from how you can quickly sketch out new code dynamically and only annotate it once things start to solidify.

Personally, I'm a fan of very strong, static type systems, so I would prefer to annotate all the things, but I understand other people have different views.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by recursive on Friday September 28, 2018 @01:51PM (#18095410)
TypeScript probably wouldn't call itself a dynamic language.
Re:Upgrading GitHub from Rails 3.2 to 5.2 by coder543 on Friday September 28, 2018 @01:55PM (#18095456)
From what I understand, everywhere that you would need to write a type, TypeScript allows you to either not declare a type at all, or put "Any" and avoid declaring a specific type. I think you can even go so far as to rename a ".js" file as ".ts", and it's fine, which is a great example of "gradual typing", and I think this all makes TypeScript a dynamic language.
Re:Upgrading GitHub from Rails 3.2 to 5.2 by zamalek on Friday September 28, 2018 @02:55PM (#18096026)
It's statically typed with opt-in dynamic (which is opt-out implicit). Sans the implicit opt-out, this is identical to C#.
Re:Upgrading GitHub from Rails 3.2 to 5.2 by coder543 on Friday September 28, 2018 @03:16PM (#18096214)
If you don't specify types at all, is that really opting out? This is valid TypeScript code:

  function foo(a, b) {
      if (a != 3) {
          return a + b
      } else {
          return "hello"
      }
  }
  
  console.log(foo(2, 5)); //prints 7
  
  console.log(foo(3, 5)); //prints "hello"
You can compile it and run it on the typescript playground: https://www.typescriptlang.org/play/

This is not like C#, where would be required to specify that every type is "dynamic". Here, you can optionally choose to specify that the types are "Any", but it's still gradual typing.

EDIT: you said "implicit opt-out"... which sounds like a synonym for "opt-in". I don't think "implicit opt-out" is a term.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by zamalek on Friday September 28, 2018 @04:37PM (#18096837)
The "implicit opt-out" is noImplicitAny[1]. That code of yours won't compile with this opt-out enabled. Edit: the "dynamic opt-in" is `any` (and is `dynamic` in C#).

[1]: https://www.typescriptlang.org/docs/handbook/compiler-option...

Re:Upgrading GitHub from Rails 3.2 to 5.2 by recursive on Friday September 28, 2018 @04:17PM (#18096694)
If it was really not a statically typed language, I'd expect this code to at least run. But it detects a type failure at compilation time despite the lack of any declarations.

    function foo() {
        return 1;
    }

    let x = foo().substring(1, 2);
Re:Upgrading GitHub from Rails 3.2 to 5.2 by coder543 on Friday September 28, 2018 @04:20PM (#18096713)
> I'd expect this code to at least run

It still compiles the code to JavaScript even with the error, and you can still run it, which makes this more of a warning than anything else.

That warning based on type inference seems like a positive feature... because there's no situation in which that code is right. You can add `: any` to the function declaration and it will stop complaining, but I wouldn't contend that the language is not dynamic because it encourages you not to make a mistake.

Re:Upgrading GitHub from Rails 3.2 to 5.2 by int_19h on Friday September 28, 2018 @06:19PM (#18097514)
The distinction between "warning" and "error" is highly arbitrary anyway. In C++, you also get a warning rather than an error if you, say, return a reference to a local, or read from an uninitialized local. You still get a binary, and it still runs. But these are 100% bugs, which is why most projects enable treat-warnings-as-errors for a lot of that stuff in C++. I'd imagine it's common with TypeScript, as well.
Re:Upgrading GitHub from Rails 3.2 to 5.2 by pi-rat on Friday September 28, 2018 @01:49PM (#18095391)
Re:Upgrading GitHub from Rails 3.2 to 5.2 by ubernostrum on Friday September 28, 2018 @03:02PM (#18096094)
How about Smalltalk?
Re:Upgrading GitHub from Rails 3.2 to 5.2 by akoncius on Friday September 28, 2018 @02:58PM (#18096062)
nowadays it’s quite good situation with php refactoring, given that php now allows type-hinting and if you keep type-hinting variables with phpdoc-style comments, IDE refactors code really well.