Tuesday, December 28, 2010

Easier object inspection in the Scala REPL

If you're like me, you spend a fair amount of time poking at objects of poorly documented classes in a REPL (Scala or otherwise...). This is great compared to writing whole test programs solely for the purpose of seeing what something does or what data it really contains, but it can be quite time consuming. So I've written a utility for use on the Scala REPL that will print out all of the "attributes" of an object. Here's some sample usage:

scala> import replutils._
import replutils._

scala> case class Test(a: CharSequence, b: Int)
defined class Test

scala> val t = Test("hello", 1)
t: Test = Test(hello,1)

scala> printAttrValues(t)
hashCode: int = -229308731
b: int = 1
a: CharSequence (String) = hello
productArity: int = 2
getClass: Class = class line0$object$$iw$$iw$Test

That looks fairly anti-climatic, but after spending hours typing objName. to see what's there, and poking at methods, it seems like a miracle. Also, one neat feature of it is that if the class of the object returned is different from the class declared on the method, it prints both the declared class and the actual returned class.

Code and further usage instructions is available on BitBucket here.

So what exactly is an attribute?

I haven't quite figured that out yet. Right now it is any method that meets the following criteria:

  1. the method has zero arguments
  2. the method is public
  3. the method is not static
  4. the method's name is not on the exclude list (e.g. wait)
  5. the method's return type is not on the exclude list (e.g. Unit/void)
  6. the method is not a "default argument" method
Please post any feedback in the comments here, or better yet in the issue tracker on Bitbucket.

39 comments:

  1. It won't really have success, I consider so.

    ReplyDelete
  2. I am really happy with your blog because your article is very unique and powerful for new reader.
    Click here:
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium Training in Chennai

    ReplyDelete
  3. Really awesome blog. Your blog is really useful for me
    Regards,
    selenium training institute in chennai

    ReplyDelete
  4. I Got Job in my dream company with decent 12 Lacks Per Annum salary, I have learned this world most demanding course out there in the current IT Market from the Data science courses in Pune experts who helped me a lot to achieve my dreams comes true. Really worth trying.

    ReplyDelete
  5. WhatsApp Status Video Download :WhatsApp introduced the status feature in 2015, in which we can share images, videos, and gifs as our story for 24 hours. Before this feature, WhatsApp had only text status option in which we can write our bio, but the new status feature is different. The story or status disappears after 24 hours and can’t be archived as still in WhatsApp.

    Boy attitude status video download for whatsApp
    Boy attitude status video download
    Boy attitude status video download

    Most romantic status video download for whatsApp
    Sad video status download
    Most Romantic status video download

    video status download for whatsApp


    we have latest & best collection of video status download for whatsapp

    ReplyDelete
  6. The registrations and auditions for the Bigg Boss 13 are going to start soon. The official list of contestants is not yet announced by the officials. That will be announced by the makers on the inaugural day which is 15 the of September. bigg boss 13 contestants name list with photo Though a few rumored names are coming up as the expected celebrity contestants of the year. They are Nia Sharma, Raghav Juyal, Punit Pathak, Divyanka Tripathi, Garima Chaurasia, Ridhima Pandit, Aditya Narayan, Jasmin Bhasin, Zain Imam, Bhuvan Bam, Chetna Pande, Krystle D’Souza, and Devoleena Bhattacharjee. This year too, the show will be back with a new theme and the star host, Salman Khan. Though the theme is not declared yet officially. Stay tuned with us to know more about the show Bigg Boss 13.

    ReplyDelete
  7. Very nice blog. It is very useful for us. Thanks for good information.Visit here :x ray camera app

    ReplyDelete
  8. I Love your article. You can visit my website : stardew valley slingshot game

    ReplyDelete
  9. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.citrix training in bangalore

    ReplyDelete
  10. Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledgez. IMSBI Training in Bangalore

    ReplyDelete
  11. Such a great word which you use in your article and article is amazing knowledge. thank you for sharing it.

    Looking for Best Training Institute in Bangalore , India. Softgen Infotech is the best one to offers 85+ computer training courses including IT Software Course in Bangalore , India. Also, it provides placement assistance service in Bangalore for IT.

    ReplyDelete
  12. Post is very useful. Thank you, this useful information.

    Learn Best SAP S4 HANA Simple Finance Training in Bangalore from Experts. Softgen Infotech offers the Best S4 HANA Simple Finance Training in Bangalore.100% Placement Assistance, Live Classroom Sessions, Only Technical Profiles, 24x7 Lab Infrastructure Support.

    ReplyDelete
  13. PNJ Sharptech is a leading Social Media Optimization company in India, specializing in handling both organic and paid Social Media Marketing (SMM) campaigns successfully. We have many years of experiencing increasing online social presence on various social media platforms such as Facebook, Twitter, LinkedIn and Pinterest, and many others. Our SMO experts have a rich knowledge of increasing traffic and maintaining the online social reputation for a long period. How our SMO services make you different from others? Our low-cost social media marketing services are very helpful to build your online reputation and increase sales.

    ReplyDelete
  14. Thank you so much for this nice information. Hope so many people will get aware of this and useful as well. And please keep update like this.
    DevOps Training in Chennai

    DevOps Course in Chennai

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. Interesting article, thank you so much for sharing this amazing blog with us. Visit Ogen Infosystem for creative Website Designing and SEO Services in Delhi, India.
    Best Website Designing Company in India

    ReplyDelete
  17. I simply wanted to thank you so much again. I am not sure the things
    that I might have gone through without the type of hints revealed by
    you regarding that situation.
    oracle certification in Chennai
    asp net training in Chennai
    C # Training in Chennai

    ReplyDelete
  18. this is a pounding blog. I wind it. you have such a lot of mastery about this depend, and as a repercussion a ton enthusiasm. You further to know a method for making individuals rally toward the back it, clearly from the reactions. Microsoft Office 2016 Product key Generator

    ReplyDelete
  19. A huge substance material as wonderfully as enormous organization. Your site justifies each and every one of the positive information its been getting. I might be advance quickly for pulling taking locale streams contents.! Good Morning Refreshing Quotes

    ReplyDelete
  20. What a nice blog post, and Many thanks for supplying this information. 스포츠토토

    ReplyDelete
  21. Thank you so much for the post perusing this one. Continue posting. Much obliged for sharing 토토

    ReplyDelete