[swift-dev] Typos while hacking on the constraint system

Mark Lacey mark.lacey at apple.com
Thu Aug 17 14:28:35 CDT 2017



> On Aug 17, 2017, at 10:28 AM, David Zarzycki via swift-dev <swift-dev at swift.org> wrote:
> 
> 
>> On Aug 17, 2017, at 13:03, Robert Widmann <rwidmann at apple.com> wrote:
>> 
>> It’s an unfortunate naming scheme, but I would hesitate to use notions like “from” and “to”, especially in CSSimplify where different matchers are handed types in whatever order variance requires.
> 
> Thanks Robert,
> 
> That is what I feared might exist. Can you give an example or two where “from” and “to” would be imprecise or wrong?
> 
>> More critical here are the scoping issues.  There are a bunch of places, especially in matchTypes itself, where type1 and type2 are re-assigned in branches during the matching process.  It makes it more of a pain to debug than it should be.
> 
> I just took a look at matchTypes(), where my last typo was, and it looks like the reassignment is largely done out of convenience, not necessity. Is this worth fixing? Most, if not all of them look easy to fix via some judicious use of ‘const’ and a few new local variables (instead of reassignment). It would make reasoning about the code easier for both newbies and experts alike.

I’m hoping to devote some time to some refactoring throughout CSSimplify with the hope of simplifying (ha!) the code and making it more accessible and easier to maintain. Eliminating reassignments would be part of that.

It would be great to see other people help make some of those improvements as well, but I would rather see renaming done as part of other clean-up and refactoring as opposed to mass renames on their own. Having said that I think it’s totally reasonable to have small commits that e.g. do small-scale renaming within a single function per commit. The specific matchTypes() function itself is a bit of a challenge in that it’s ~1000 lines of code and really needs to be simplified and split up, which I think will aid in producing fewer issues with reassignment and fewer similar-but-slightly-different names.

In general I would like to see names that are more visually distinct, but there aren’t always clearly great names. One convention used in some of the code is to use ‘first’ and ‘second’ which correspond to the first and second types in the constraint that the types are coming from. Despite these names lacking any real specificity, they are very visually distinct.

Mark


> 
> Dave
> 
>> 
>> ~Robert Widmann
>> 
>>> On Aug 17, 2017, at 9:55 AM, David Zarzycki via swift-dev <swift-dev at swift.org> wrote:
>>> 
>>> Hello,
>>> 
>>> More than once, I’ve made typos while hacking on the constraint system because the key variables are often named “type1” and “type2”. Beyond sharing 4 out of 5 characters, the ‘1’ and the ‘2’ are right next to each other on the keyboard, and typing the other by accident results in code that still compiles.
>>> 
>>> Are “type1” and “type2” really the most apt names? Is something preventing better names from being used? Wouldn’t “fromTy” and “toTy” be better and less typo prone?
>>> 
>>> Thanks,
>>> Dave
>>> _______________________________________________
>>> swift-dev mailing list
>>> swift-dev at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-dev
>> 
> 
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev



More information about the swift-dev mailing list