What is a "stub" in Intellij Cursive? - cursive

The following message from time to time appears in Cursive:
"Your project requires namespaces which need stubs to be generated"
When I first saw that I thought it was something along the lines of generating code, in the way rails might generate code stubs for you. Obviously I don't want that, this is clojure, so I pressed ok anyway, and it seemed not to do anything. So what does this message mean?
What exactly (or even approximately) is a "stub" is in this context?

According to the Cursive User Guide https://cursive-ide.com/userguide/macros.html
Stubs are "source files containing empty function stubs which it can index for use in the editor."

Related

Ruby 'compile' while coding

Using Java big IDEs compile my code while it is written so that errors are detected before runtime.
Is that possible with Ruby too? Actually I code in a Text editor. Errors are detetected at runtime only.
Is that possible with Ruby too?
If by that you mean "compiling", then no. If you mean "edit-time error detection", then also no.
Smart IDEs, like RubyMine, can guess/detect some errors, but only simple cases. And they are often confused by ruby's dynamic nature. (can't find location for a method, even though it's defined within the project. Or the opposite, find too many false positives).
In ruby, you simply can't know what does a piece of code do without running it.

TDD with zero production code

I was going through 'The Clean Coder' by Bob Martin where i read about the discipline to write test before any Production code.
However, TDD articles for asp.net in msdn show classes and method stubs being created and then unit tests were generated from those stubs.
I want to know whether I can write all unit tests before writing a single line of code in Business logic layer.
Edit: 1. My idea was to refactor to the extent where i change the entire class-relationship structure itself if needed. If i start from a stub then i would have to re-write the tests in case the class and method itself was wrong.
Edit: 2. Apart from that the thrust is on data-driven test, so if I use interfaces how would i write complete test where i have passed all the fields and since interfaces need to be generic i don't think they'll have all the properties. At best interfaces can have CRUD stub defined.
Thanks in Advance.
Sure you can. What's stopping you?
(Though typically, you would write one test at a time, rather than writing them all at once. Writing them all up-front smacks of Big Design Up Front, aka Waterfall. Part of the point of TDD is that you design as you go and refactor as needed, so you end up with something that's only as complex as you actually need in order to satisfy your requirements -- it helps you avoid YAGNI.)
If you follow classic TDD principles, then you write a test to fail first, you run it and watch it fail, and only then do you write the necessary code to make it pass. (This helps make sure that there's not a subtle error in your test.) And if you're testing code that doesn't exist yet, the first failure you expect is a compiler error.
This is actually important. You're testing code that doesn't exist. Of course the compile should fail. If it doesn't, then you need to find out why -- maybe your tests aren't actually being compiled, or maybe there's already a class with the same name as the new one you're thinking of writing, or something else you didn't expect.
There's nothing stopping you from writing a non-compilable test first, and then going back and making it compile. (Just because Microsoft didn't understand TDD when they wrote their testing tools doesn't mean you can't do it yourself.) The IDE might step on your toes a bit while you do (completing the names of existing classes instead of leaving the names you're trying to write), but you quickly learn when to press Esc to deal with that.
Visual Studio 2010 lets you temporarily switch Intellisense into a "test-first" mode, where it won't step on your toes in this situation. But if you happen to use ReSharper, I don't think they have that feature yet.
It does not matter if you create the method stubs or the tests first. If you write the tests first, your editor might complain about method/class stubs not existing.

Why is VS2010 looking for framework source code when Just My Code is enabled?

Googling this yields lots of entries on HOW TO step through Framework code. I'm trying to find out how NOT TO step into.
First check: Yes, "Enable Just My Code" is checked in the Tools->Options->Debugging. That is supposed to keep VS2010 from looking for source code when you are stepping through a framework function (or anything else that you don't have the source to, as I understand it.)
It's not. I'm trying to step through my code, using F11, and, if I get careless and don't switch to F10 (to step over a function call) when I get to a function that is in a library, then it throws up a dialog asking where the source for that call is, and when I cancel out of it (since I don't have the source), it aborts my Debug, and I have to start all over.
How can I avoid this behavior. As I understand the documentation, this is NOT the way it is supposed to work. And where do we go for support when it's not working?
You can do this by simply not loading symbols for the framework.
In the Symbols window, there is an option for "Automatically symbols for:" depending on the option you choose you can explicitly exclude those modules, or only specify your own modules.
I assume you are using the All modules, unless excluded option, so you should exclude the framework modules.
If you actually own the framework you can also add a StepThrough attribute to any framework functions you want to step through. See http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerstepthroughattribute.aspx.

(Ruby) Compiling dynamic applications for Windows?

Does anyone have any insights regarding compiling Ruby code for Windows? I've tried both "Ruby2Exe" and "OCRA", but both present their own issues. Ruby2Exe keeps presenting vague or confusing warnings such as "can't modify frozen string". OCRA on the other hand seems to want to run your script and assumes that there are no dynamic items.
For the record, my script accepts command line arguments as well as reading in and parsing a text file. OCRA doesn't like this aspect at all, and actually throws the warnings in my code as if I tried to run the script.
Anyway, if anyone has any quality means by which to compile ruby code for Windows, I'm all ears.
As a bit of an FYI, my goal with this particular script is to send email over SMTP. It is part of a larger non-ruby application, but the framework is incapable of sending email. I find Ruby enjoyable and rather easy to work with but don't wish to have every end user install Ruby -- hence, the need/desire to "compile" it.
I'm on a short time table and can't really afford to expend resources on writing this in C++, etc. However, if anyone has any insights on any existing Windows-compatible libaries/applications, do tell.
Much appreciated.
"OCRA on the other hand seems to want to run your script..."
The constant Ocra is defined at compile-time but not at run-time. So you can include logic based on whether or not the Ocra constant is defined. For example:
app = MyApp.new
if not defined?(Ocra)
app.main_loop
end

In Ruby, what's the equivalent of Java's technique of limiting access to source in a cowork situation?

In Java when you compile a .java file which defines a class, it creates a .class file. If you provide these class files to your coworkers then they cannot modify your source. You can also bundle all of these class files into a jar file to package it up more neatly and distribute it as a single library.
Does Ruby have any features like these when you want to share your functionality with your coworkers but you don't want them to be able to modify the source (unless they ask you for the actual .rb source file and tell you that they want to change it)?
I believe the feature you are looking for is called "trust" (and a source code control repository). Ruby isn't compiled in the same way that Java is, so no you can't do this.
I have to say your are in a rough position, not wanting to share code with a coworker. However, given that this is an unassailable constraint perhaps you could change the nature of the problem.
If you have a coworker that needs access to some service provided by a library of yours, perhaps you could expose it by providing a web/rest service instead of as a .rb file.
This way you can hide your code behind a web server, and if there is a network architecture that allows for low latency making these service calls, you can effectively achive the same goal.
Trust is a lot easier though.
edit:
Just saw this on HN: http://blog.astrails.com/2009/5/12/ruby-http-require, allows a ruby file to include another file through http instead of the filesystem.
Ruby is
A dynamic, interpreted, open source programming language with a focus on simplicity and productivity.
So like all interpreted languages, you need to give the source code to anyone who want's to execute your program/script.
By the way searching "compiled ruby" on google returned quiet a few results.
I don't think there is one. Ruby is purely an interpreted language, which means ruby interprets your source code directly in order to run it. Java is compiled, so there's an intermediate bytecode (the .class). You can obfuscate your ruby if you really wish, but it's probably more trouble than it's worth.
Just to make sure you realize, however, upwards of 95% of Java can be decompiled back into source using various free utilities, so in reality, Java's compilation isn't much better than distributing Ruby source.
This is not a language specific problem and one that can be managed more effectively through source control software.
There is a library called ruby2c that compiles a subset of Ruby into C code (which you can then compile into native code, if you want).
It was actually originally written as a Ruby code obfuscator (but has since been used for lots of other stuff, including Ruby Arduino development).

Resources