What is an environment in programming? - environment

This may seem like a simple question, but I keep getting caught up in it. The word environment seems to be thrown around a lot, but I can't find a definite answer for my question. Environment variables, and and software development environment both have the word environment. Java Runtime Environment also uses this word, but does it mean the same for everything? Is this word even that significant?
Hope this makes sense.

Related

What is "/path/to"?

I've been doing web programming for some time now, and don't consider myself so much of a total newbie but I still don't understand what "/path/to" is. People use that code a lot, and I used to think it's just a way to refer to main path. But I started wondering why so many people use that syntax so uniformly, because it's confusing if it's meant to be NOT taken literally. Most people would actually type in "/path/to".
So I tried searching for "/path/to" on google, but this is something that's hard to search on a generic search engine, so no luck. So I decided to ask here. Is "/path/to" some kind of jargon that people use to refer to something? If yes, what does it exactly refer to? If no, then how does it work internally?
This is just a placeholder for an actual path in your environment. I usually use it when I want to abstract from the path in question. It does not matter and the reader/user of my code will likely have it different. So I prefer to clearly indicate what places he should amend.
Other examples of this sort:
GET http://example.com
ssh username#host
/path/to/project and similar constructs are used in documentation and blog posts to abstract away details that vary on different machines and for different people. For example, I might be working on a project on my Linux machine that is at /home/code-apprentice/src/my-cool-ruby-project. At the same time, you are working on a project on your Windows machine that you put at C:\Users\Vlad\Projects\MyEvenBetterRubyProject. We both are reading the same blog article to implement a feature. The detail of the exact path where we each store our project doesn't matter for the particular part of Ruby on Rails that we are using. The notation /path/to/project is just a convenient and concise placeholder to describe the root of the project that varies between our machines.

Navigating a large ruby codebase, like rails

I've been a java developer for most of my career, and developed and maintained some pretty large code bases.
now that I've been developing in rails for a while I've left my IDE behind and I want so start looking at the actual rails source. I've mainly been using the github interface which is actually quite good but I wondered if there were tips and techniques from more seasoned ruby devs?
What I'm missing mainly is my trusted eclipse features like "find usage" or "goto implementaton". Perhaps a paradigm shift is in order... please enlighten me :P
Since you're an Eclipse user I'd recommend Rubymine. It gives you a lot of the same features and has good integration with rails. It has good support for jumping to implementation/usage, although this is a harder problem in ruby than java. When Rubymine can't determine which implementation is the correct one, you're usually given a list of all matching methods.
I personally use Vi and haven't had trouble navigating rails projects, usually it's a matter of convention and familiarity that just comes with working on the same project for enough time. I default to using grep or find for usages etc.
The problem is that things like "goto implementation" and its ilk may require deep knowledge of the runtime. Some methods may not exist until after an initialization or mixin process. Duck typing means that anything that responds to a message is a potential type candidate.
I'm reasonably happy with IntelliJ (Rubymine), but you won't find the same level of navigational support you get from a language like Java, where most everything is known up front. It's simply less navigable than Java code, IMO.
The things that can be known, like explicitly-defined methods, "obvious" calls, and so on are navigable, and IMO right now IntelliJ does it the best, but I haven't used an Eclipse Ruby environment for some time, so the situation may be different now--but I'm often surprised at how well it does do, considering the circumstances.
That said, I flip back-and-forth between IntelliJ, TextMate, Sublime Text 2, and Emacs. TextMate is nearly useless to me because of its single-pane design. For quick stuff or small projects, it's adequate.

Do ruby on rails programmers refactor?

I'm a Java programmer who started programming Ruby on Rails one year ago. I like the language, rails itself and the principles behind them. But something that bothers me is that Ruby programmers don't seem to refactor.
I noticed that there is a big lack of tools for refactoring in Ruby / Rails. Some IDE's, like Aptana and RubyMine seem to offer some very basic refactoring, but nothing really big compared to Eclipse's Java refactorings.
Then there is another fact: most railers (even the pros) prefer some lightweight editors, like VIM or TextMate, instead of IDEs. Well, with these tools you just get zero refactoring (only regex with find/replace).
This leaves me this impression that rails programmers don't refactor. It might be just a false impression, of course, but I would like to hear the opinion of people who work professionally with ruby on rails.
Do you refactor? If you do, how do you do it,with which tools? If not, why not?
Definitely yes, there is a different reason for the tool disparity
An IDE is more practical to construct for Java
Java's strict typing and documented grammar make it possible to write language-parsing IDE tools
Ruby's duck typing and documented-by-the-Yacc-source grammar make it quite difficult to do so.
An IDE is more needed for Java
Java's verbosity makes code-writing and code-rewriting tools desireable.
Ruby's extremely terse nature combined with the typically-no-type-declarations (of course they do appear inline with Type.new) make such things optional.
Combining the two...
So the combination of really hard to write coupled with not actually needed results in the balance tipping in favor of people's favorite editors.
Giving up vi(1) for an IDE is something I would rather not do, but I do with Java because I need the IDE to write my interface implementations and such, and the fact that it parses Java makes it useful in code completion. Since with Ruby it can't and I don't need it anyway, I stick with vi(1) and TextMate.
Summary
Since you aren't buried in code, it's possible to refactor with a few reasonable edits. But while on the subject of "other Ruby developers", my Ruby question is: why does everyone (except me it seems) use function parens? Because in a few % of situations they are needed, and so the "inconsistency" is disturbing?
Yes.
Most Rails programmers try and follow a Test first, write code to pass the test, then refactor the code BEFORE they go onto the next test.
Do ALL rails/ruby programmers... probably not, but as far as a 'vibe' or 'feel' in this community, I'd say it's something that is preached and practiced enough that it happens more times than not.
There is no need for IDEs imo. VIM, emacs and/or textmate is enough for Ruby and most rails programmers. I guess Java needed more compiling or something, what do I know about that though, as I've only programmed in Ruby. Why do all Java programmers use IDEs (since I'm generalizing).
RoR developers do refactor a lot. But most importantly they do it because they can do it easily.
If you keep to the main principle of RoR - Do not Repeat Yourself - and spent some time on code design (which means you didn't happen to create a huge chunk of monolithic code), nothing can stop you to rewrite a piece of code, whatever is in your mind (generalization, speedup, improving readability, etc.). The built-in testing/benchmarking/profiling functionality of Rails is at your service to check if you achieved your goal without sacrificing already existing and working functionality.
The editor is totally independent of the code, therefore you could even use Notepad for coding (I'm not a command-line fanatic, I prefer a bit more 'graphical' editors like Gedit).
Having spent a lot of time in both Java and Ruby (with a good bit of back-and-forth of late, from Eclipse to/from Textmate) I agree that certain kinds of refactorings are harder in Ruby. This is less a consequence of poorer IDEs for Ruby than it is the fact of static typing vs. dynamic typing and the difficulty of writing refactoring tools for a dynamic language. To a large degree manual/regex driven refactoring is easier in Ruby than it would be in Java because of the terseness of Ruby code -- there's just less of it --, but nevertheless something as simple as renaming a method is not as straightforward in Ruby as it is in Java. The benefits of Ruby vs. Java are (imo) greater by far (and you'll just have to use Ruby in production for a few months to get a real feel for just how much you'll love it), but one drawback is the lack of the same robust refactoring that you're used to in tools like IDEA and Eclipse.
EDIT: And just to be clear -- I don't do any less refactoring in Ruby per se than Java, but it seems I need it less for Ruby. But when I do I rely on unit tests rather than the compiler as I would in Java.

Why does Lua default to global variables?

My favourite language these days is Lua. I have only one issue with it, why on earth is its default behaviour that variables in functions are global? In the similar language Icon there is a keyword "global" that is used when one really wants to use a global instead of the natural behaviour to default to local (I was bitten by this again five minutes ago). I would feel better about this if somebody could tell me the rational behind it (like the scoping difficulties that I know cause the absence of a "continue" keyword in Lua).
See Why aren't variables locally scoped by default? in the Lua uFAQ.
It certainly feels easy to only explicitly declare globals when they are in a local context. The short answer is that Lua is not Python, but there are actually good reasons why lexically-scoped local variables have to be explicitly declared. See the wiki page.

Worth migrating to Rake?

Is it really advantageous to move to Rake from ant?
Anyone migrated from ant and find something monumental?
FYI: Current environment is Ant for J2ME builds
I would say yes, but I have a different perspective than a Java-environment guy, because I'm a .NET-environment guy. I had written and maintained a non-trivial build script (clean, generate-assembly-info, build, test, coverage, analysis, package) in msbuild (MS' XML-driven NAnt effort) and it was very painful:
XML isn't friendly; it's very noisy
No-one else on the team was interested in learning it to the point of performing more, and more useful, automations; so high bus factor (ie, if I get hit by a bus, they're stuck with it)
It did not lend itself to refactoring or improvement - it was one of those 'touch-at-your-peril' things, you know?
It needed custom C# tasks to be written to run the various tools the build needed (though to be fair, often these are written by the vendors)
In about a work-week's worth of my time (got to love empty offices at Christmas time!), I've learned enough ruby+rake to replace the whole thing with a shorter (in terms of LOC) script with slightly more functionality, and more understandability (I hope, anyhow; haven't had it reviewed yet).
It benefits from:
- It's a new language, but a real language. My team-mates like learning new languages, and this, while a thin excuse, is still an excuse ;-) This might mitigate the bus-factor if I'm right.
- It's a short hop (I gather) from here to capistrano, the automated/remote/distributed deployment tool from the RoR world. Despite being an MS-stack shop, we're gonna be using that in combination with IIS7 finally having a CLI config tool.
So, yeah. Your mileage may vary, but it was worth it for me.
Rake is great if you want:
Access to a real programming language; conditionals and loops are all dead-simple, compared to Ant (in which they are nigh-impossible)
File format that is easy to read and can be syntax checked
More intuitive/predictable assignment of values to variables
Rake is bad for you because:
You need to provide a lot basic of the tasks (like running javac, creating jar files, etc.) yourself. Projects like Raven might help, but it seems geared toward auto-downloading dependencies and not so much automated a build/deploy process. Plus, the documentation is a bit lacking.
Most java tools that can be automated are done as Ant tasks, which aren't easily runnable from Rake; starting up the JVM can be annoying at build time
You might want to check out buildr as well. It's a higher-level build-tool built on rake. IMHO it takes a lot of the good features from maven, and throws away the bad-ones. I haven't used it in anything big myself but I know people who have and are quite happy with it.
Another tool that you might want to check out is Gant if ant isn't meeting your needs. It adds full blown scripting support to ant but allows you to re-use your ant tasks as needed. It really depends on what you don't like about ant.

Resources