Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

wat

Name: Anonymous 2011-08-14 23:38

So in C++ I could do

class A {
    int B();
}

int A::B()
{
    return 1;
}


i.e. I could keep my class definition and the code for the methods separate, but I can't figure out how to do the same thing in C#.  Do I really have to use "partial class A {}" in front of everything?

Name: Anonymous 2011-08-14 23:51

There is no reason to keep class definitions and code separate. It's a holdover from the days of K&R where compile times where actually a problem and all compilers were single pass.

Name: Anonymous 2011-08-14 23:53

>>2
Well I can count at least two reasons I should be able to do it:

1) I like it better that way.  Keeping structure and details separate makes things more readable IMO.

and
 
2) It's always been that way, and there was no reason to take the ability away.

Name: Anonymous 2011-08-15 0:07

>>1
You're doing it wrong. Since the compilation model doesn't require header files, there's no big reason to break up class implementations and spread it across multiple translation units, except in the case where you want to keep code written by a programmer and code generated by a tool separate, and that's the reason partial classes were introduced into C#. So stop trying to use partial classes incorrectly.

Just keep all methods in the class definition. There is no need for type declarations or forward declarations in C#, the compiler can figure it all out at build time.

Just do:

class A
{
    private int data;

    public A() {
        data = 100;
    }

    public int B() {
        return 1;
    }

    public int C() {
        return 2 + data;
    }
}

Name: Anonymous 2011-08-15 0:12

>>3
Your brain is damaged. Different languages do things differently. The more you try to force idioms from one language into another where they do not apply, the more trouble you will run into. Keeping structure and details does not necessarily make things more readable, you only think that because you've been conditioned to think that.

It's always been that way, and there was no reason to take the ability away.

Take a look at Smalltalk, the first object-oriented language. It didn't do it that way. And neither did Pascal/Delphi, on which C# was somewhat based (the designer of C# was the lead architect at Borland who worked on Turbo Pascal and Delphi).

I suggest you follow the old adage: ``When in Rome, do as the Romans do.''

Name: Anonymous 2011-08-15 0:32

>>5
Different languages do things differently.

C++/CLI and C# are very similar otherwise, and I can do it there.

I suggest you follow the old adage: ``When in Rome, do as the Romans do.''

I'm totally with you as a general rule, I just really, really want to be able to do this one thing this way. >:I  And you'll never convince me the C# way is easier to work with or maintain.  Having the entire class consist solely of one longass lump of code without a separate definition is like having a book with no table of contents.

Name: Anonymous 2011-08-15 0:37

i see OP's point. the class definition is like a folded up summary.

Name: Anonymous 2011-08-15 1:47

Smalltalk is shit.

Name: Anonymous 2011-08-15 2:46

>>6
The table of contents is the documentation automatically generated by the compiler using C# doctag comments. Learn to use them. You're doing it completely wrong, and other C# programmers will hate you for it, and any code you write will be utterly useless, you would be laughed at if you used it in a portfolio for finding a job.

Name: Anonymous 2011-08-15 2:58

>>9
lol C# jobs and programmers

Name: Anonymous 2011-08-15 5:17

>>1

It's a feature to ensure you keep your classes & methods small. :3

Name: Anonymous 2011-08-15 5:37

>>1,10-11
/g/, get out of here.

Name: Anonymous 2011-08-15 5:51

>>12
This is /pro/g//. We are here. That is all.

Name: Anonymous 2011-08-15 6:11

>>1,6,7
the class definition is like a folded up summary.

Incidentally, you IDE has a keybinding for folding every method body leaving only the "folded up summary". You might have had noticed that it uses this mode by default when you try to go to definition of a framework class or interface, if you used the tool for more than a couple of minutes before forming a strong opinion about how it should be used.

Name: Anonymous 2011-08-16 12:16

>>2

Compile times are still a problem when you deal with the Mighty C++!

Name: !!1ILcdKBYf7nyXyy 2011-08-16 12:24

There is no reason to keep class definitions and code separate. It's a holdover from the days of K&R where compile times where actually a problem and all compilers were single pass.

Try again Burger King boy. I could cite a few C code examples where the (conformant) compiler had to/and still does, have to make mulitple passes over the code.

Name: Anonymous 2011-08-16 12:39

>>16
Disregard what I said in the other tnread, you're still a moron.

Name: !!1ILcdKBYf7nyXyy 2011-08-16 12:51

>>17
I'm not the fuckwit that thinks the compiler were always single pass. Perhaps if you would have written some actual production level C code in your life you wouldn't have much such an idiotic statement. But alas, your limited mental capacity doesn't take you that far. Now go back to serving another customer or go replace another network switch you general labor monkey.

Name: Anonymous 2011-08-16 14:26

>>18
>thinks C is the master language
>looks up the power continuum and sees nothing but weird languages
>couldn't work his way out of a lexical closure to save his mother
laughinggirls.apng.gpg.zip.aes256

Name: Anonymous 2011-08-16 14:30

>>19
Go back to /g/, blubfagstorm.

Name: Anonymous 2011-08-16 14:42

>>20
why'd you drop the tripcode, fagstorm?

Don't change these.
Name: Email:
Entire Thread Thread List