Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Taboo: java?
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Andy




PostPosted: Wed Nov 08, 2006 4:39 pm   Post subject: (No subject)

Give him a break wtd, when you first pick up programming (not a programming language, but programming in general), its hard to get used to it. From his posts, you can clearly tell that he doesnt have much experience in anything.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Nov 08, 2006 4:42 pm   Post subject: (No subject)

I just roll my eyes because that's exactly how I learned. I learned more than one language at a time, and it actually made things easier. It made it easier to see concepts when I saw them expressed in more than one way.
[Gandalf]




PostPosted: Wed Nov 08, 2006 7:27 pm   Post subject: (No subject)

Indeed, although maybe for the better in the end, learning two languages at the beginning can be the more difficult path. Let's say it's C++ and Java... Where do I put those brackets for the array again?

As for the rest of that post... Very cliche.
Quote:
I do program both but it is time to move on to something much more challedging like java. Afterwards when i have somewhat mastered java I plan to learn c++.
wtd




PostPosted: Wed Nov 08, 2006 9:07 pm   Post subject: (No subject)

[Gandalf] wrote:
Indeed, although maybe for the better in the end, learning two languages at the beginning can be the more difficult path. Let's say it's C++ and Java... Where do I put those brackets for the array again?


I never advocate learning one Big Scary language at first, much less two. Smile
Andy




PostPosted: Thu Nov 09, 2006 3:48 am   Post subject: (No subject)

just out of curiosity, what were the languages you started with wtd?
wtd




PostPosted: Thu Nov 09, 2006 10:25 am   Post subject: (No subject)

TI-82 BASIC back in high school calculus. Our school had no computer science classes.

I worked with HTML and Javascript for a bit when I went to Cornell, but while I was there I studied Perl and then Python at the urging of a friend. All of those things I did on my own.
Null




PostPosted: Thu Nov 09, 2006 10:16 pm   Post subject: (No subject)

Quote:

Finally, I believe c++ is extremely easier than Java.


At first, maybe. But do you have any idea how this code snippet works?
I sure as hell don't.

(It is a piece of code posted by a member named Narue at programmingforums.org)

c++:

#include <iostream>
#include <locale>

template <typename CharT>
class numfmt : public std::numpunct<CharT> {
    private:
        CharT sep_;
        int group_;

        CharT do_thousands_sep() const { return sep_; }
        std::string do_grouping() const { return std::string( 1, group_ ); }
    public:
        numfmt( CharT sep, int group )
            : sep_( sep ), group_( group ) {}
};

int main() {
    numfmt<char> *fmt = new numfmt<char>( ',', 3 );
    std::cout.imbue( std::locale( std::locale(), fmt ) );

    for ( double n = 0, i = 1; n < 10; n++, i *= 20 )
        std::cout << std::fixed << i << '\n';
}


The snippet alters the formatting of numbers so that a comma is displayed every 3 digits and then prints out a few sample numbers.

[quote=output]
1.000000
20.000000
400.000000
8,000.000000
160,000.000000
3,200,000.000000
64,000,000.000000
1,280,000,000.000000
25,600,000,000.000000
512,000,000,000.000000
[/quote]
ericfourfour




PostPosted: Thu Nov 09, 2006 10:43 pm   Post subject: (No subject)

Quote:
Finally, I believe c++ is extremely easier than Java.
I already went over this. I'm not going to explain it again.

About the code snippet. No i don't know how it works but I'm sure if I took the time to look it over I could (I'd have to look in the numpunct class and locale to get a full idea). Meh, why don't I take a shot at it?

c++:
numfmt( CharT sep, int group )
            : sep_( sep ), group_( group ) {}
This part of the code initializes sep_, and group_ using an initialization list. Sep_ is the separator (the comma in this case) and group_ is the amount of characters that are grouped between the commas. This means that you could potentially have a comma (or even an exclamation mark) every 5 characters.

c++:
CharT do_thousands_sep() const { return sep_; }
        std::string do_grouping() const { return std::string( 1, group_ ); }
This part lost me. It looks like the first one just returns the separator and the second one creates a string with the group_ length and then returns it.

And that's about as far as I got. The rest I couldn't figure out without looking at the class inherited or what is in locale.
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Thu Nov 09, 2006 11:08 pm   Post subject: (No subject)

ericfourfour wrote:
Quote:
Finally, I believe c++ is extremely easier than Java.
I already went over this. I'm not going to explain it again.

It's just that this is such a ridiculous statement, most often made by people who haven't explored the languages beyond:
c++:
#include <iostream>

int main()
{
    std::string name;
    std::cout << "Please enter your name: ";
    std::cin >> name;
    std::cout << "Your name is: " << name << std::endl;
    return 0;   
}

And:
Java:
import java.io.*;
public class Input {
    public static void main(String[] args) throws IOException {
        String name;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Please enter your name: ");
        name = in.readLine();
        System.out.println("Your name is: " + name);
    }
}

And don't know about Java's Scanner class:
Java:
import java.util.Scanner;
public class Input {
    public static void main(String[] args) {
        String name;
        Scanner in = new Scanner(System.in);
        System.out.print("Please enter your name: ");
        name = in.nextLine();
        System.out.println("Your name is: " + name);
    }
}

Not to say that that applies to you, of course...
ericfourfour




PostPosted: Thu Nov 09, 2006 11:38 pm   Post subject: (No subject)

That's pretty good Gandalf. I'll have to look into it.

Anyway, I was using input as a simple example. It's not complicated (I even made a wrapper for it so I don't have to write so many lines every day). Maybe, Java isn't as hard as I think.

When its written out in a comparison (the one Gandalf displayed) Java actually makes more sense. I don't even know what the <<, or >> does. All I know is it gets the input and when used with the string stream they point toward the variable being changed and point away from the variable being assigned the value.

I guess I used the wrong wording. If c++ is difficult my wording would have said java is extremely difficult. Which it isn't. In my opinion working with c++ more organized which in turn makes it easier, but that's just me.
wtd




PostPosted: Thu Nov 09, 2006 11:54 pm   Post subject: (No subject)

ericfourfour wrote:
I don't even know what the <<, or >> does.


Considering how important these operators are in terms of standard C++, you'd be well advised to learn more about them.

<< is the insertion operator, and >> is the extraction operator. << inserts a value into an output stream. >> extracts values from an input stream.

As fucntions can be overloaded in C++, so too can operators. The << and >> operators are overloaded for different types of streams and values.

Consider:

code:
class Foo { };

ostream& operator<<(ostream& out, const Foo& f)
{
   return out << 42;
}

int main()
{
   Foo f;

   cout << f << endl;
}


What do you think this program will output?
ericfourfour




PostPosted: Fri Nov 10, 2006 3:20 pm   Post subject: (No subject)

wtd wrote:
What do you think this program will output?

I have no clue but I'm guessing 42 but the >> was never used so it may be nothing.

If it is done the way I think its done, you overloaded the >> operator and somehow it was called by using <<. It took in the parameters cout and f. By using cout it output 42.

What was the point of having

c++:
const Foo& f

I can only speculate here but I guess it is so it only gets called if you use Foo. Is this correct?
wtd




PostPosted: Fri Nov 10, 2006 3:23 pm   Post subject: (No subject)

ericfourfour wrote:
wtd wrote:
What do you think this program will output?

I have no clue but I'm guessing 42 but the >> was never used so it may be nothing.


Oops. Typo. Smile
ericfourfour




PostPosted: Fri Nov 10, 2006 11:10 pm   Post subject: (No subject)

Phew, I thought I was seeing things. It makes a lot more sense now. Very Happy
wtd




PostPosted: Fri Nov 10, 2006 11:28 pm   Post subject: (No subject)

Consider also:

code:
class Foo
{
   private:
      int _bar;

   public:
      int bar() const
      {
         return _bar;
      }

      friend ostream& operator<<(ostream& out, const Foo& f);
      friend istream& operator>>(istream& in, Foo& f);
};

int main()
{
   Foo f;

   cin >> f;
   cout << f << endl;
}

ostream& operator<<(ostream& out, const Foo& f)
{
   return out << f._bar;
}

istream& operator>>(istream& in, Foo& f)
{
   return in >> f._bar;
}
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 3  [ 31 Posts ]
Goto page Previous  1, 2, 3  Next
Jump to:   


Style:  
Search: