4 ms·
Sure there is. Imagine you had this function: int f(void) { int x = 1; return x * 2; } Then pretend that later you wanted to call f an
by kbp 9y ago
Sure there is. Imagine you had this function:
int f(void) {
int x = 1;
return x * 2;
}
Then pretend that later you wanted to call f and provide your own value of x for it to transform, but you realise that f doesn't take a parameter, so you go to move the x declaration in f into its parameter list. What you really want to do here is delete the first element of the parameter list, and then move the first expression in its next sibling list (the function body) to the end of it. C syntax doesn't make this easy for editors to do, but the operations can still be thought of in terms of lists.
You get nested expressions whenever you use if or a loop or call a function. C programs might be flatter on average than Lisp programs, but there's still plenty of structural editing you could do. Another example is moving an expression out of or into a loop, without concern for how many lines it takes up, whether it's a function call or a loop or anything.
The difficulty that C syntax creates for editing operations like this isn't C not having the need for Paredit-style editing, it's C not having good support for it.
- thedirt0115 9y agoTooling is getting better for non-Lisp languages. In C#, with Visual Studio and ReSharper, for example, you could highlight the "int x = 1;" line, and hit your keyboard shortcut for ReSharper:Introduce_Parameter, which would do pretty much exactly what you're saying. Same for turning a chunk of code into a method, etc.
- gleenn 9y agoThe tooling is there, it's not bad, and it is constantly getting better. I use Cursive in IntelliJ to do all my Clojure programming. A lot of others also use Emacs but Cursive is an amazing plugin imho. It does the vast majority of things I want from an IDE, like jumping to definitions, some refactorings, switching easily to relevant test files. Paredit took a while to get used to but I immediately miss it when programming anything else.
- deleted 9y ago[deleted]
- jstimpfle 9y agoRegarding the loop: that's exactly what I described, you just move lines and fix the indentation. It's super quick. There just isn't significant nesting in good code. It's almost always bad style to nest function calls. In statement-blocks you don't have the "trailing parentheses" problem that you have in LISP, since the closing brace is on its own line - so it really boils down to cutting and pasting lines >90% of the time. Aside: in original C, this is how you wrote functions: int f(x, y) int x; int y; { int z; ... }
- kbp 9y ago> Regarding the loop: that's exactly what I described, you just move lines and fix the indentation. The experience you get with Paredit is not the same experience you get with C and vi, because you have to be concerned with things at the character level to make the transformation. What single command do you use to move the function call, for loop, label, or do-while loop after the closing brace of the current block into this block, whether it's 1 line or 100? What if you have something like f(x, y * 2) and you decide that you want to put y * 2 into a variable instead? Do you write every argument to every function on its own line? Again, if you want to do things the C way in Lisp, it's not like Lisp makes it hard to do those kinds of edits. Things like Paredit are popular because people find them more efficient to use. Editors can support Paredit-like editing in C, but it's much more difficult to accomplish because of limitations with C's syntax.