-
Notifications
You must be signed in to change notification settings - Fork 7
Description
I've been watching a lot of YouTube videos by proponents of different languages. Having worked in numerous languages myself -- sometimes switching between 4 or 5 in a single day (hence my "polyglot-jones" moniker) -- it drives me nuts that the language designers can't agree on a common set of syntax for even the most basic of concepts. It occurs to me that the IDE could and should be able to help here. If you are working on a Python file and you type in a for-loop using C++ syntax, the IDE shouldn't complain, it should just translate it for you. It should just DWIM (Do what I mean).
It further occurs to me that an extension such as this one can get us a fair ways towards that goal -- as a proof of concept, if nothing else. All it would take is to allow for the "typo" that we match on to be longer than just a word. In fact, just allowing for the translations to be described using Regex would be a great start.
Already, this extension can help a Python developer (for example) to autocorrect on these:
nil => None
null => None
true => True
false => False
this => self
throw => raise
(except that it will be too aggressive with string constants and comments).
Adding regex would provide the ability to do things like these (in a limited fashion):
for (i=1; i<99; i++) => for i in range(99):
my_list.join(", ") => ", ".join(my_list)
my_string.contains("foo") => "foo" in my_string
private my_var => _my_var
else if => elif
I'm going to experiment with this in my fork. Some questions to be answered in the meantime:
- Do we allow both vim-style and regex in the same dictionary? Or do we have separate dictionaries? Or, do you have to pick one style or the other?
- On the issue of not being too aggressive with comments and string constants, assuming we can discern the context, what notation should we use to specify in which context(s) a particular translation applies?
- If you can think of additional examples of differing syntax for the same semantics, please let me know. The more complicated, the better.