Server Help

Trash Talk - why do people say a real programmer uses printf?

hellzlaker - Sun Apr 13, 2008 7:42 pm
Post subject: why do people say a real programmer uses printf?
why do poeple say that a real programmer uses printf() over cout? To me they look pretty much the same except for printf() you do more writing and its smaller icon_confused.gif

like isnt it just easier to do

Code: Show/Hide

int age;
cout<<"enter your age: ";
cin>>age;
cout<<"you entered "<<age;


then
Code: Show/Hide

int age;
printf("Enter your age: ");
scanf("%d",age);
printf("you entered %d",age);


Samapico - Sun Apr 13, 2008 7:53 pm
Post subject:
it's pretty much the same, typing-wise.

There was a big discussion among the Great Geeks of this forum about this... one of the 2 is "more efficient", apparently, but since you don't print something 1000 times a second, it doesn't change anything.

It's like the people who say Firefox is the only worthy browser, vs IE users... there are fanboys on each side, but they have no idea how much their fight is worthless...
Dr Brain - Sun Apr 13, 2008 7:59 pm
Post subject:
Mostly because "real programmers" use C, rather than C++.

I use the term loosely, of course, since the lower level you are, the more "real" you are. Making the people who cast the silicon the real programmers, I guess...
k0zy - Mon Apr 14, 2008 3:56 pm
Post subject:
/me waits for MrEkted to comment on the issue

I still remeber the endless discussions about that... ^^
And why MrEkted uses goto. That was fun to read, too.
Samapico - Mon Apr 14, 2008 5:18 pm
Post subject:
I always thought the formatting was pretty flexible with printf... never used cin/cout, though.
Dr Brain - Mon Apr 14, 2008 6:14 pm
Post subject:
Anything you can do with one, you can do with the other. There are arguments for efficiency and abstraction on the C++ streams side, but they're fairly trivial things either way.

If you use C++, then you use iostreams. If you use C, then you use fprintf.
Animate Dreams - Mon Apr 14, 2008 10:04 pm
Post subject:
fprintf is file print, right? I think you mean iostream/printf, or fstream/fprintf
Doc Flabby - Tue Apr 15, 2008 6:20 am
Post subject:
i find the printf syntax easier to read and understand, but thats just personal preference.
Dr Brain - Tue Apr 15, 2008 8:06 am
Post subject:
IOStreams encompass the console and file io, and fprintf(stdout, "x") and printf("x") do the same task.
hellzlaker - Tue Apr 15, 2008 8:32 pm
Post subject:
I just read a topic somewhere else and turns out in the C# you dont use cout or printf but you use their new function Console.WriteLine("Hello World!");

and its closer to printf but i dont get why do they have to keep changing shit?

this is how the input age works in c#

string input;
int age;
Console.WriteLine("Please enter your age");
input = Console.ReadLine();
age = Int32.Parse(myInput);
Console.WriteLine("You entered {0}", age);



now just tell me how gay is first impression of c# is?


also did Ekted have an acount on MGB? I read some stuff on wiki how ekted said that every one is a noob on SS and thats why he quit, or something like that
tcsoccerman - Tue Apr 15, 2008 9:35 pm
Post subject:
c# owns.
Samapico - Tue Apr 15, 2008 9:58 pm
Post subject:
the console is only used for debugging purposes most of the time anyway... getting input from it, and especially validating is a pain in the butt, and ugly tongue.gif
Blocks - Wed Apr 16, 2008 1:52 am
Post subject:
Mr Ekted uses goto? I never knew him, but I thought better of him.
Doc Flabby - Wed Apr 16, 2008 4:57 am
Post subject:
hellzlaker wrote:
I just read a topic somewhere else and turns out in the C# you dont use cout or printf but you use their new function Console.WriteLine("Hello World!");

and its closer to printf but i dont get why do they have to keep changing shit?

this is how the input age works in c#

Code: Show/Hide

string input;
int age;
Console.WriteLine("Please enter your age");
input = Console.ReadLine();
age = Int32.Parse(myInput);
Console.WriteLine("You entered {0}", age);


You could also write it like this.
If you think c# is diffferent take a look at Pascal tongue.gif
Code: Show/Hide

Console.WriteLine("Please enter your age");
int age = Int32.Parse(Console.ReadLine());
Console.WriteLine("You entered " + age);


Nothing wrong with using goto, the problem is when it gets overused by newbies, it has a valid place in programming imo.
Animate Dreams - Wed Apr 16, 2008 11:41 am
Post subject:
hellzlaker wrote:
I just read a topic somewhere else and turns out in the C# you dont use cout or printf but you use their new function Console.WriteLine("Hello World!");

and its closer to printf but i dont get why do they have to keep changing shit?

this is how the input age works in c#

string input;
int age;
Console.WriteLine("Please enter your age");
input = Console.ReadLine();
age = Int32.Parse(myInput);
Console.WriteLine("You entered {0}", age);



now just tell me how gay is first impression of c# is?


You can actually do it the Java way too, I think, with concatenating strings. At the very least, you could do:

string output = "You entered" + age;
Console.WriteLine(output);, but you can probably do that inside of the parentheses. It's just whichever way you choose.

There's certainly a place for both. Most people prefer the first method, with the {0}, but... I had a project recently in my C# class where we were given a project, but we were told that we would later have to re-do the project using Windows programming instead of console input/output. So the idea was to code in a way that could be easily converted. Each class was supposed to have a Show() function that would just print all of the information that class was storing to the screen. So instead of having the function use Console.WriteLine(), I just had the function return "Var1: " + var1 + "\nVar2: " + var2; so that, in the main function, you could just Console.WriteLine(class.Show()); That way, when I had to re-do the project, I wouldn't have to change the classes at all.

Well, that was the idea. Instead I'm changing the project so it can work with a database, so I'll probably have to change the classes anyway, but whatever.
Samapico - Wed Apr 16, 2008 12:43 pm
Post subject:
I'm pretty sure you need to use the .toString() method:
Code: Show/Hide
Console.WriteLine("You entered " + age.toString() );

D1st0rt - Wed Apr 16, 2008 2:21 pm
Post subject:
the + operator is overloaded so you don't need to

Alternatively, you could even do
Code: Show/Hide
Console.Write("You entered ");
Console.WriteLine(age);


If you're doing a lot of string processing you should use String.Format (which is what you showed earlier with the {0}) or a StringBuilder for performance reasons.

@Ani: if you put the Show() method body into ToString() you would be able to Console.WriteLine(class);
k0zy - Wed Apr 16, 2008 2:57 pm
Post subject:
Blocks wrote:
Mr Ekted uses goto? I never knew him, but I thought better of him.


MrEkted is a great programmer.
In his opinion functions should only have one return.
He uses goto to break out of the funtions and jump to the return in case an error occurs.
That's an okay use for goto.

And I think it was him who said that cout actually uses printf internally.
hellzlaker - Wed Apr 16, 2008 4:04 pm
Post subject:
well i guess i got used to C++ so much that all other languages look weird, but PHP, JAVA they kinda feel like C++, and C of course
Dr Brain - Wed Apr 16, 2008 7:49 pm
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
And I think it was him who said that cout actually uses printf internally.


He did. He was wrong.
k0zy - Thu Apr 17, 2008 2:14 am
Post subject:
Did you guys know that Java features a goto like construct? It can be used to break out of nested loops for example.

I just found that out a few weeks ago.
Dr Brain - Thu Apr 17, 2008 7:44 am
Post subject:
Yes, and the entire Java library is written without using it. In the Java specification, they say that it's bad practice to use it. I think they only put it in as a concession.
CypherJF - Thu Apr 17, 2008 8:22 am
Post subject:
I actually saw that the other week when I was decompiling a few java class files; it used a couple of goto statements.
Animate Dreams - Sat Apr 19, 2008 8:39 pm
Post subject:
D1st0rt wrote:
@Ani: if you put the Show() method body into ToString() you would be able to Console.WriteLine(class);


elaborate

You mean, within my class definition, define a string ToString() method?
Doc Flabby - Sun Apr 20, 2008 9:03 am
Post subject:
Animate Dreams wrote:
[..]
elaborate

You mean, within my class definition, define a string ToString() method?

Basically override the ToString method.

Example
Code: Show/Hide

public class MyClass
{
   public override string ToString()
   {
      return "String Representation of Class";
   }
}

Samapico - Sun Apr 20, 2008 1:03 pm
Post subject:
interesting
Animate Dreams - Sun Apr 20, 2008 3:19 pm
Post subject:
badass

so myclass.tostring is automatically called when someone tries to treat the class as a string?
k0zy - Sun Apr 20, 2008 4:31 pm
Post subject:
Welcome to the wonderful world of Duck Typing.
D1st0rt - Sun Apr 20, 2008 4:49 pm
Post subject:
Animate Dreams wrote:
so myclass.tostring is automatically called when someone tries to treat the class as a string?


Not exactly. What's happening in this case is that you're actually calling the WriteLine method that takes an object as a parameter and it calls ToString. What you're talking about will happen if you're adding it to a string literal ("hello, " + object) because the + operator is overloaded, but you can't just throw an Object anywhere something calls for a String.
Cheese - Sat Apr 26, 2008 1:07 am
Post subject:
personally i prefer cout and cin, because you have to type less, and its easier to read.

ie > ff

and goto is always fun =)
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group