Reversing a Sentence with Java - No Loops

In summary, reversing a sentence with Java without using loops involves splitting the sentence into an array of words, creating a new string and adding the words in reverse order with a space in between, and finally printing out the reversed sentence. This method can be useful for tasks such as creating a user-friendly display of data or for implementing algorithms that require reversed input.
  • #36
TylerH said:
I prefer tabs to spaces because any good editor or IDE let's the user adjust tab length. Or... do you mean that you have you tab length set to 3?
No, in most places I've worked, tabs were pretty much banned. I also don't like to use them, personally. Mostly, it's because not everyone tends to have their tabs set to the right length, and it becomes a mess when it's not set right. It seems like it shouldn't be a problem, but my experience has shown that it's a problem more often than I would have though. Basically, I don't want everyone who reads the code to have to mess with their tab stop settings. Spaces "just work".

Mind you, any editor I use is generally configured to give me 3 spaces (or whatever the standard is) when I press the tab key. So not much of a difference in practice.
 
Technology news on Phys.org
  • #37
There's no difference in practice, *until someone wants something other than 3 spaces*. If everyone wants 3 space tabs, then all they have to do is set their tab stop settings to 3. It's when people differ in opinions, as they tend to, that the use of tabs becomes a godsend. In what case do tabs cause a mess?
 
  • #38
TylerH said:
There's no difference in practice, *until someone wants something other than 3 spaces*. If everyone wants 3 space tabs, then all they have to do is set their tab stop settings to 3. It's when people differ in opinions, as they tend to, that the use of tabs becomes a godsend. In what case do tabs cause a mess?
It's not so bad in a closed team, really.

But let's say you have it done with tabs 4 spaces long, and you send me your code. I load it in vi (which I do use frequently) where my tabs are 8 characters long by default. First, I probably have to look up how to change the tab stop settings, because I don't usually have to do that. And it's not always immediately obvious what the proper setting is. With spaces, it never comes up. Things can end up wrapping in a messy way viewing it at 8. But mostly, it's code indented like this:
Code:
int function(int a, int b,
             int c, int d)
{
}
Now imagine that to indent the "int c" line and line it up with "int a" above (a common practice - I do that for example), you use a tab followed by some spaces. If the tab stops aren't the same, it won't line up properly anymore, making it look messy.

It's not a huge thing (and I'm certainly not suggesting you're doing it wrong), but it's been enough of an annoyance that a lot of places I've worked make spaces the standard. Of course, the most important thing is that everyone agrees to do it the same way. Resolving change control conflicts because people don't agree on indentation is rather annoying.
 
  • #39
I see. I've come across that once. My solution was to deal with the offset, like so:
Code:
int function(int a, int b,
    int c, int d) // 5 spaces being my normal tab stop
{
}
I'll admit that the offset is annoying, but better than having to go through and change spaces to tabs so I can use my tab stop settings. :P

As for not knowing how to set vi's tab stop, which I don't either, I would say it's the employee's job to know his tools.

But, you're a professional with (probably) years of experience of dealing with others code. And I'm a one-man programming-team, who happens to still be in high school, and has never had to deal with the annoyance of making my code readable to anyone but me(not that I'm overly sloppy). So I really can't argue from the perspective of someone who would know which is better for a [more-than-one-man] team wide coding standards.
 
  • #40
Grep said:
Except I'm guessing you wouldn't normally be missing a closing curly brace to close the function. :wink:
Right! I removed a pair of braces that served no purpose, and I guess that somehow screwed up my count, plus I was being sloppy. It's fixed now.
Grep said:
So you normally use 3 space indenting? You'd be one of the only people I've ever met that does that other than myself. I learned it when I was writing safety critical software where every little thing was scrutinized, and proper indentation (and thus clarity) was very important. I do it because it makes it obvious when someone has used tab characters for indenting since pretty much nobody has their tab stops set to 3. Same reason for you? Just curious.

I usually use only two spaces per level of indentation. The reason for this is that the code that I and others write appears in online documentation. If tabs are used and there are many levels of nesting, some lines of code make the page very wide so that you have to scroll sideways to see the long lines. With two spaces per indent level, the code hierarchy is evident, and you don't have to scroll to see it.
 
  • #42
Mark44 said:
I usually use only two spaces per level of indentation. The reason for this is that the code that I and others write appears in online documentation. If tabs are used and there are many levels of nesting, some lines of code make the page very wide so that you have to scroll sideways to see the long lines. With two spaces per indent level, the code hierarchy is evident, and you don't have to scroll to see it.
Ah, makes sense. Mind you, I usually consider that, by the time it gets to that, someone has too many levels of nesting in the first place. And I don't mean to imply that you nest code excessively. :smile:

TylerH said:
The solution to spaces v tabs: http://nickgravgaard.com/elastictabstops/
I admit I like that solution. Of course, the problems in getting this idea in general use are likely self-evident. He'd have to cover a whole lot of editors, and do some serious marketing to get this to see the light of day. So I'm not hopeful to see this in general use. But I, personally, think it's a great idea.
 

Similar threads

Replies
2
Views
2K
Replies
2
Views
2K
Replies
3
Views
1K
Replies
1
Views
6K
Replies
2
Views
1K
Replies
1
Views
6K
Replies
2
Views
2K
Back
Top