4 ms·
I am a fan of python. when developing python and needing a breakpoint I just write >> import pdb;pdb.set_trace() in the respective line and can then execute th
by werner34 13y ago
I am a fan of python.
when developing python and needing a breakpoint I just write
>> import pdb;pdb.set_trace()
in the respective line and can then execute the code till that point and have all the current variables available in the console.
This was missing for me when I started doing stuff in scala, so I hacked something to be able to do the same in Scala and jump straight to the REPL(unfortunately variables need to be passed explicitly here, but most of the REPL functionality works:
https://gist.github.com/anonymous/7693857 https://gist.github.com/anonymous/7693857
- babs474 13y agoI always wonder why more languages don't have this, which I call repl at point, or repl with context. Not sure if there is a more standard name. Even clojure with its generally awesome repl support doesn't have it. I created a library a while ago that does something very similar to what you did, for the groovy language. http://aaronbabcock.blogspot.com/2011/11/groovy-debugging.html http://aaronbabcock.blogspot.com/2011/11/groovy-debugging.ht... It avoided having to pass in variables explicitly by using groovy's AST transform ability (macros) to examine the code for which variables would be in scope and pass those into the repl automatically. I wonder if something similar would be possible in scala?
- _pmf_ 13y ago> I always wonder why more languages don't have this, which I call repl at point, or repl with context. Users of gdb call it "debugging".
- werner34 13y agoAh, I forgot to mention gdb as well. gdb and python hooked me on this way of developing.
- babs474 13y agoNo I think they are related but different. For instance with pdb or the clojure repl I"ll add entire new functions or classes and try them out. With gdb or jdb that might be theoretically possible but it certainly is not convenient or commonly done. Typically your stretching things with a complicated one liner expression. But you are right concepts are pretty close, its just that I find a lot of things that call themselves "debuggers" don't have the ability to add new code. Things that call themselves "repls" dont' have the ability to stop at a point or context like a debugger. pdb being the exception. Why can't we have tools that do both things well.
- Estragon 13y agoIn clojure, you can do it with a macro [1]. There's also the recent schmetterling [2] [1] https://coderwall.com/p/xayyvq https://coderwall.com/p/xayyvq [2] https://github.com/prismofeverything/schmetterling/ https://github.com/prismofeverything/schmetterling/
- werner34 13y agoWell, I looked into it but gave up soon-ish because it looked to annoying and my hack was sufficient for me at the time.
- edwinnathaniel 13y agoAny decent Java IDEs can do this for you. I'm not sure if that capability covers Scala. You can set a breakpoint (conditional or not), and have every thing within that context available for you. The next step is to launch an "Evaluation window" where you can execute Java code. If you were to set the breakpoint at the web-application level (as opposed to plain Java process/class/console-app), you can get information of the Threads and Frames as well. This techniques have been available for quite some time in the IDEs... that is provided you're not allergic to IntelliJ/NetBeans/Eclipse. Best part: no code change. I have no comment for those who prefer VIM/Emacs and bemoaned the lack of powerful stuff they got from other environments.
- werner34 13y agoYes, if you have an IDE you don't have this problem at all. I am more with the VIM/Emacs crowd though I guess. I didn't know though that you could create an "evaluation window" in Eclipse. I really liked the refactoring features in Eclipse though and miss them sometimes.
- edwinnathaniel 13y agoThis article goes over useful debugging technique using Eclipse: http://www.cavdar.net/2008/09/13/5-tips-for-debugging-java-code-in-eclipse/ http://www.cavdar.net/2008/09/13/5-tips-for-debugging-java-c... - You can set breakpoint only for "Exception" - You can set "Step Filtering" to avoid JDK standard classes (or libraries that you know won't cause the bugs) - The Expression Evaluation also supports code-assist/code-completion It's really tough to beat IDEs like Eclipse and IntelliJ these days with plenty contributors and strong companies behind them churning new features everyday.