lainchan / λ

Do What I Mean

sizeof · 2017-04-19 23:59
Last night I was talking to someone about preferences in software, and we had a rather strong difference of opinion. They prefer small and simple tools with little configuration and very easily-predictable behaviour. I don't mind large and complex tools with lots of configuration if it can save me work later. Their text editor of choice is nano; mine is emacs. Another example they gave is that a friend of theirs uses a tool called j, which fuzzy-matches its argument against directories you have recently visited, in order to jump to the one you mean. They said such a tool is too magical for them. I realised that this is essentially the difference between dwim ("do what I mean") tools, which infer what you want from context, and manual tools which require more direction. A simple example is the emacs comment-dwim function, which toggles comments on lines. Sometimes the behaviour we want is not what the dwim code will do automatically; hence emacs doesn't just have comment-dwim, it also has comment-line and comment-region, for if you really do want doubly-commented lines. What do you think about dwim functionality? Do you prefer it, or do you prefer software which doesn't try to be so clever? What are the ways in which we can build dwim functionality into our software? Toggles are just one approach; you could imagine auto-suggesting macros (in an editor) or functions (in a shell) based on common operations the user does.
Gyula Kovacs · 2017-04-20 00:45
I like DWIM for removing thought from interactions that seem natural to me, such as your examples. Here's a very simple function that I wrote in spirit of that: (defun kill-dwim () (interactive) (apply 'kill-ring-save (if (region-active-p) (list (region-beginning) (region-end)) (list (point-at-bol) (point-at-eol)))))
mynaemissnek · 2017-04-20 01:10
>>528 Interactions between users and software can be compared to interactions between humans: To yield the expected results, different types of software require distinct behaviours by the user and thus are leading to different means of interaction --- pretty much relatable to distinct "types" of persons requiring different forms of interhuman interaction. Do you know the kind of person that always tries to find meaning in every little action of yourself and therefore accumulates inaccurate assumptions about your intentions? "The fuarrrk no, just because I don't eat cornflakes every morning it doesn't mean I don't like cornflakes in general." (I'm talking to you, Karen). And maybe you also know a person that just understands you and alway notices when you have a soykafty day or something. Both kind of prototypes of persons could be compared with "do what I mean tools" --- their behaviour is either utterly annoying or really pleasant. That's probably why simpler tools like vim etc. are still around, they just don't have any inaccurate assumptions about what you are and what you want, unlike google search (yeah, comparing apples to oranges here but you get the idea).
Backus · 2017-04-20 10:48
I think Python has some really great editors that are purpose built for the Python language like Eric, SPE, Boa Constructor, DrPython. No one has made any purpose built editors for Javascript or Ruby but instead rely on plugins to editors like Sublime, Atom, Eclipse. Id really like to see editors where dependency managers and build tools are built into the UI of the editor and could be handled visually through a graphical interface instead of having to enter commands into a console all the time
Turner · 2017-04-20 12:59
In the programming world, the DWIM equivalent would be "weak typing." For those unclear with the rather ambiguous terminology, weak typing is where the language tries to automatically coerce unfit types to a "correct" alternative, in order to prevent type errors. An example would be a language automatically converting numbers into strings when you try to concatenate them with other strings ("a"+1 = "a1"). I think that weak typing was a sort of programming "fad". C uses it heavily for numbers in order to have intuitive behavior even though integral types are distinct. PHP and Javascript used it heavily in an attempt to keep code from crashing at all costs, even if that means spitting out garbage at the end. Most languages include it slightly, for instance the string concat example, or some sort of automatic integer -> floating point promotion. C++ takes great advantage of configurable weak typing in the form of "implicit conversions." However a lot of people now realize that weak typing is a pain. It usually doesn't do what you intended it to. And when it does exactly what you want, thats because you memorized the specific weak typing rules, which is a lot of cognitive load. At best, you save a few keystrokes. At worst, your code has invisible and difficult to trace bugs. That's probably why languages like Python avoid much more weak typing than most dynamic languages, and why some languages with much more powerful type systems, like Haskell, are able to avoid weak typing altogether (while still solving the issues that weak typing "patches" in languages like C). I think that in programming, where it is essential to have a complete understanding of the system and its behavior, DWIM methods do NOT WORK, since they only introduce more rules (cognitive load).
Hagbard Celine · 2017-04-20 19:29
I am attempting to write a dwim program in Common Lisp, which has a list of pattern/command pairs, accepts a list of arguments, and then runs the command for the matching pattern (giving the user a list if there are multiple). I'm trying to do this because, on reflection, a lot of my workflow is very predictable. I already have some dwim-functionality in my zshrc: function command_not_found_handler () { if [[ -e $1 ]] && [[ -z $2 ]]; then if file $1 | grep ' text\b' &>/dev/null; then $EDITOR $1 else file $1 fi elif grep $1 ~/.ssh/config &>/dev/null && [[ -z $2 ]]; then ssh $1 elif type command-not-found &>/dev/null; then command-not-found $1 else echo "$1: command not found" >&2 fi } So I can just type a filename or a hostname and it'll do something reasonably sensible if it's not already a command. But there are other patterns, such as "if all the files exist and end in .torrent: if they're not in directory X or Y move them to directory X; if they're already in directory X move them to directory Y." I don't particularly enjoy expressing logic in shell (even though zsh makes this nicer than bash), so I decided to learn a lisp. But this is my first real Common Lisp program, so who knows if I'll manage to implement everything I want.