c# is a good way to learn c

  • Thread starter Thread starter Montrose...
  • Start date Start date
There are myriad problems with this.
1. There is only a limited number of gurus to go around.
2. Most gurus don't like writing boring business software.
3. This presumes that the hiring managers can tell which hires are
.......

I fully agree with you on this.
It appears that you have a lot of experience in this.

The use of language is basedon what is needed in that domain.
And in my opinion, a good programmer will use the tools he has available at
that time for that job.

Although I do admit, that since I have background of assembler and
electronics, I would not like creating VB programs.
So I tend to stay on the Delphi/C++/C# side of the road. And I would also
tend to create a library of classes to do the things, so no fast hacks in my
case. But other people my prefer the VB side and databases. It is developer
dependend.
 
Hi Spooky, Ya writ: << At some point one would hope for an employer that
can at least attempt to read C++ code, Java code -- heck, any code,
or maybe run a code analyzer to find the more common bugs. >>

Automated code analyzers are futile,
Code is as it does, only testing finds bugs.
 
Hi Bruce_Wood, Re: The kind of code you want,

What programs do you have that run too slow ? None, I'll bet.

And even if you did have speed concerns,
they probably could be solved by just upgrading your LAN,
internet connection, hard drive, DVD burner, printer, etc.

I also bet that you don't spend endless years/money perfecting GUIs,
....second, or even third class, will do,
so C#'s dialog/forms editors are quite good enough for you.

As far as maintaining code... upgrades, bug fixes, etc.,
there's always a learning curve, even with C#.

From showing my code, for example my HTM_TXT.CPP,
which demos how my X.CPP converts HTML files into plain_text files:
http://www.Cotse.NET/users/jeffrelf/HTM_TXT.CPP
I found that no one here was willing to take the time to learn
my standard methods... which is totally understandable.

But I also found that no one here could produce anything half as good.
I think that's because the STL and C# make people lazy,
they tend to rely on the built-in stuff too much.
 
Jeff_Relf said:
But I also found that no one here could produce anything half as good.

Man, you really have created your own little fantasy here, haven't you?
 
Olaf said:
So you can optimize for speed, and you can optimize for functionality and
you can optimize for fast changes and optimize for readibility and optimize
for group usage. :-)

Optimize for speed is nice for OS kernal and image processing tools.
Optimizing for functionality is for example adding plug-ins to extend the
program.
Optimize for fast changes could be a tax payment software that must change
every year according to the new rules.
Optimize for readability for other people for example if the program is
created by a contractor, and next time he is unavailable, someone else must
be able to extend the program.
Optimize for group usage, is to make other people use your library to
develop their programs.

Most of the times it is imposible to have all of those in one program.

Is your name really 'Olaf' ?
 
But I also found that no one here could produce anything half as good.
I think that's because the STL and C# make people lazy,
they tend to rely on the built-in stuff too much.

I hope at least someone could write more readable code, your example is VERY
unreadable.

Use some {}'s and don't put them on the same line as any code.
That would make your code a lot more friendly towards other developers.

/Søren
 
But I also found that no one here could produce anything half as good.
I hope at least someone could write more readable code, your example is VERY
unreadable.

Use some {}'s and don't put them on the same line as any code.
That would make your code a lot more friendly towards other developers.
Yes but that slows down the compiler, because it has to process all the
blanks and CR and LF characters.
And it is less performant because you need additional bytes to store these
addtional blinks and CR and LF chracters too, so you have less memory, less
disk space, and that would be not a proof that you be able to create fast
code. ;-)

Just kidding!!!

I do know from experience that some programmers think that creating
one-liners are faster programs, but I have done enough reverse engineering
by looking at the actual created assembler code, and I do know that it is
simply not true. Sometimes the one-liner created additional hidden temp
variables slowing it down. Everything depends on your compiler quality.
 
Hi Olaf_Baeyens ( and Sean_Hederman ),
Re: My LowerCaseNG() which converts a Copy of a string like
"Alt.OS.Windows-XP, Comp.OS.Linux.Advocacy"... removing all the spaces,

You showed me: << string name = "Alt.OS.Windows-XP, Comp.OS.Linux.Advocacy";
Console.Write(name.ToLower()); >>

That's not a copy and the spaces are still there.

At any rate, that was a poor example of my LoopTo() macro,
below is a better one... oh, and by the way,
the flexibility/readability of macros is what I demand... not speed.

Decode the following from 7-bit to 8-bit,
for example, following the UTF-8_B, UTF-8_Q, and iso-8859 standards
( a space has been added before the first ? to disable conversions )
= ?UTF-8?B?MTIzNDU2Nzg5XzEyMzQ1Njc4OV8xMjM0vw==?=
= ?utf-8?Q?=70=69=75=73=20=70=72=69=63=65?=
= ?iso-8859-1?Q?Lin=F8nut?=

Note, UTF uses two 8-bit chars, so just going to 8-bit once is not enough,
a line might well require two passes.
Various decoding methods are required, including Base64.

Here are the standards that I'm demonstrating:
#define LOOP while ( 1 )
#define Loop( N ) int J = - 1, LLL = N ; while ( ++ J < LLL )
#define \
LoopTo( StopCond ) \
while ( Ch && ( Ch = ( uchar ) * ++ P \
, Ch2 = ( uchar ) P [ 1 ] \
, Ch ) \
&& ! ( StopCond ) )
#define Eq ! strcmp
#define Eqi ! stricmp
#define EqN ! strncmp
#define EqiN ! strnicmp

typedef char * LnP ; typedef unsigned int uint ;

int rv;

__inline int RaisC ( LnP P ) { return * P = toupper( * P ); }

int HexToN( int C ) { if ( isdigit( C ) ) return C - '0' ;
if ( RaisC ( ( LnP ) & C ) >= 'A' && C <= 'F' )
return 10 + C - 'A' ; return -1 ; }

__int64 ER ( __int64 X, __int64 Y ) { return X > Y ? X : Y ; }
__int64 er ( __int64 X, __int64 Y ) { return X < Y ? X : Y ; }

This is my 7 bit to 8 bit converter to demonstate the above standards:

LnP _7_to_8( LnP _7 ) { static LnP B; static int Sz_B ;
rv = ER( 200, strlen ( _7 ) + 1 );
if ( Sz_B != rv ) { free ( B ); B = ( LnP ) malloc( Sz_B = rv ); }
strcpy( B, _7 );
LOOP { P = B ; int Repeat = 0 ;
LOOP { int Ch = 1, Ch2 = 0 ; int UTF_8 ;
LoopTo (
Ch == '=' && Ch2 == '?'
|| ( UTF_8 = ( Ch == 194 || Ch == 195 )
&& ( Ch2 & 0xC0 ) == 0x80 ) );
if ( ! Ch ) break ;
if ( UTF_8 ) { memmove( P, P + 1, E -- - ( P + 1 ) + 1 );
* P = ( Ch & 3 ) << 6 | Ch2 & 0x3F ; continue; }
LnP T = P ; P += 2 ;
if ( ! Repeat ) Repeat = EqiN( P,"UTF-8", 5 );
LoopTo ( EqiN( P, "Q?", 2 ) || EqiN( P, "B?", 2 ) );
if ( ! Ch ) break ;
int Q = EqiN( P, "Q?", 2 ); P += 2 ;
memmove( T, P, E - P + 1 ); E -= P - T ; P = -- T ;
uint X, By, Cnt ; X = By = Cnt = 0 ; T = P ;
LoopTo ( Ch == '?' && Ch2 == '=' )
if ( Q ) {
if ( Ch == '=' ) {
Ch = HexToN( Ch2 ); Ch2 = HexToN( P [ 2 ] ) ;
if ( Ch >= 0 && Ch2 >= 0 ) { * P = Ch * 16 + Ch2 ;
memmove( P + 1, P + 3, E - ( P + 3 ) + 1 ); E -= 2 ; } } }
else { X <<= 6 ; X |= A_63 [ Ch ]; if ( Ch != '=' ) By ++ ;
if ( ++ Cnt < 4 ) continue;
LnP XP = ( LnP ) & X ; XP += 3 ;
Loop( By * 6 / 8 ) * ++ T = * -- XP ; X = By = Cnt = 0 ;
memmove( T + 1, P + 1, E - ( P + 1 ) + 1 );
E -= P - T ; P = T ; } if ( ! * P ) break;
memmove( P, P + 2, E - ( P + 2 ) + 1 ); E -= 2 ; }
if ( ! Repeat ) break ; } return B ; }

// A_63 is a sparsely populated table
// to convert from Base64's ( MIME ) printable ASCII characters
// ( A-Z, a-z, 0-9, +, / ) to integers between zero and 63.
// _63_A goes the other way.

char A_63 [ 'z' + 1 ], _63_A [ 64 ];

main() { LnP CC = "Aa0+/"; int X = -1 ;
Loop( strlen ( CC ) ) {
int L = J > 2 ? 1 : J == 2 ? 10 : 26 ; char C = CC [ J ] - 1 ;
Loop( L ) A_63 [ _63_A [ X ] = ++ C ] = ++ X ; }

// Note the space before the first ? must be removed by hand
// before testing.

printf( "%s",
, _7_to_8( "= ?UTF-8?B?MTIzNDU2Nzg5XzEyMzQ1Njc4OV8xMjM0vw==?= "
"= ?UTF-8?B?MTIzNDU2Nzg5XzEyMzQ1Njc4OV8xMjM0vw==?=" ) );
printf( "%s",
, _7_to_8( "= ?utf-8?Q?=70=69=75=73=20=70=72=69=63=65?= "
"= ?utf-8?Q?=70=69=75=73=20=70=72=69=63=65?=" ) );
printf( "%s",
, _7_to_8( "= ?iso-8859-1?Q?Lin=F8nut?= "
"= ?iso-8859-1?Q?Lin=F8nut?=" ) ); LOOP; }

Except for the main(), the above code is from X.CPP:
http://www.Cotse.NET/users/jeffrelf/X.CPP

You showed: <<
int swapped=(((byte) iOriginal)) << 24 | ((byte) (iOriginal >> 8)) << 16 |
((byte) (iOriginal >> 16)) << 8 | ((byte) (iOriginal >> 24)); >>

Good work, but you can't inline that in C#,
C++ allows me to inline select functions ( using __inline )
even when I'm debugging ( using the complier's /Ob1 switch ).

Speaking of that, C++ can link with the non-debug CRT/LIBs
and still have all the debugging options I need.

Did you try my version in C#... and did it work ? :

typedef unsigned char * uint_8_P ;

int Swap_32 ( int X ) { uint_8_P P = ( uint_8_P ) & X + 4 ;
return * -- P << 24 | * -- P << 16 | * -- P << 8 | * -- P ; }

main() { printf( "%x", Swap_32( 0x84838281 ) ); }

I ask because the above code does not work in MS_C_7_1,
and I think it's a bug... it doesn't evaluate the four -- P decrements
left to right like it should... it decrements them all at once, like P -= 4 ;

Re: The way Outlook wrapped your code,

40tude_Dialog lets you marks lines you don't want wrapped.
My hyper-custom newsreader, X.EXE,
never automatically wraps anything... as a rule.
( all wrapping must be done manually )

Nevertheless, You could've just wrapped it yourself, like this:

90 mov eax,esi // eax=iOriginal
92 and eax,0FFh // (byte) iOriginal ( converting int to byte )
97 shl eax,18h // (byte) iOriginal<< 24
9a mov edx,esi // edx=iOriginal
9c sar edx,8 // iOriginal >> 8
9f and edx,0FFh // ((byte) (iOriginal >> 8))
a5 shl edx,10h // ((byte) (iOriginal >> 8)) << 16
a8 or eax,edx // ((byte) iOriginal)) << 24
// | ((byte) (iOriginal >> 8)) << 16
aa mov edx,esi // edx=iOriginal
ac sar edx,10h // iOriginal >> 16
af and edx,0FFh // ((byte) (iOriginal >> 16))
b5 shl edx,8 // ((byte) (iOriginal >> 16)) << 8
b8 or eax,edx // ((byte) iOriginal)) << 24
// | ((byte) (iOriginal >> 8)) << 16
// | ((byte) (iOriginal >> 16)) << 8
ba mov edx,esi // edx=iOriginal
bc sar edx,18h // iOriginal >> 24
bf and edx,0FFh // ((byte) (iOriginal >> 24)
c5 or eax,edx // ((byte) iOriginal)) << 24
// | ((byte) (iOriginal >> 8)) << 16
// | ((byte) (iOriginal >> 16)) << 8
// | ((byte) (iOriginal >> 24)
c7 mov ebx,eax // copy to the swap variable.

You concluded: << So very compact in my opinion.
Also note not temporary memory values, pure register operations
SO LIGHTNING FAST!!!!!

If you would check C++ code then you will also see something like this.
There goes the mystery that C# would be slower ! ! ! ! It is not !
And I even didn't use the unsafe keyword ! Pure managed. >>

That is amazing.

You wrote: << iOriginal=Class1.Swap_32(iOriginal); translates to:
15 mov ecx,esi
17 call dword ptr ds:[009750E0h]
1d mov edi,eax
1f mov esi,edi

static public int Swap_32(int iOriginal) {
return (((byte) iOriginal)) << 24 | ((byte) (iOriginal >> 8)) << 16 |
((byte) (iOriginal >> 16)) << 8 | ((byte) (iOriginal >> 24)); }

This translates to:

00 push ebp
01 mov ebp,esp
03 sub esp,8
06 push edi
07 push esi
08 mov esi,ecx
0a xor edi,edi
...
0c mov eax,esi
0e and eax,0FFh
13 shl eax,18h
16 mov edx,esi
18 sar edx,8
1b and edx,0FFh
21 shl edx,10h
24 or eax,edx
26 mov edx,esi
28 sar edx,10h
2b and edx,0FFh
31 shl edx,8
34 or eax,edx
36 mov edx,esi
38 sar edx,18h
3b and edx,0FFh
41 or eax,edx
43 mov edi,eax
...
45 jmp 00000047
47 mov eax,edi
49 pop esi
4a pop edi
4b mov esp,ebp
4d pop ebp
4e ret

So in this case you have the expected overhead of
executing a call and setting up a stack. >>

Very interesting... thanks. But as I said above,
only macros give me the flexibility/readability that I demand,
....I'm not so concerned about speed.
 
Hi Olaf_Baeyens ( and Soren_Reinke ),

The way I use whitespace is the most readable to me, of course,
and I expect you to change it to taste too.

Speed was never my concern.

An added benefit is that this allows me to track where I've been reading,
as the whitespace there will have changed.
 
Hi Soren_Reinke, Function is the only measure of code, not whitespace.
I leave it to the reader to invest the time it takes to read my code,
and, hopefully, change the whitespace to his tastes.
 
Use some {}'s and don't put them on the same line as any code.
Yes but that slows down the compiler, because it has to process all the
blanks and CR and LF characters.
And it is less performant because you need additional bytes to store these
addtional blinks and CR and LF chracters too, so you have less memory,
less
disk space, and that would be not a proof that you be able to create fast
code. ;-)

Hahaha that was a good one, i'll remember that one :)

Have a nice weekend.

Best regards
Søren Reinke
 
You showed: <<
int swapped=(((byte) iOriginal)) << 24 | ((byte) (iOriginal >> 8)) << 16 |
((byte) (iOriginal >> 16)) << 8 | ((byte) (iOriginal >> 24)); >>

Good work, but you can't inline that in C#,
C++ allows me to inline select functions ( using __inline )
even when I'm debugging ( using the complier's /Ob1 switch ).
As a function no, as far as I know.
That is why I showed the static method version too and tried to show what
the assembler code would looks like.
Did you try my version in C#... and did it work ? :
The one above? Sure, I didn't daret to put here stuff that are not based on
real testing.
I hope this evening/night when I install C++ at home to see what the C++
code will create for assembler code.

But it should be very close to the one I shown.
typedef unsigned char * uint_8_P ;

int Swap_32 ( int X ) { uint_8_P P = ( uint_8_P ) & X + 4 ;
return * -- P << 24 | * -- P << 16 | * -- P << 8 | * -- P ; }

main() { printf( "%x", Swap_32( 0x84838281 ) ); }

I ask because the above code does not work in MS_C_7_1,
and I think it's a bug... it doesn't evaluate the four -- P decrements
left to right like it should... it decrements them all at once, like P -= 4 ;
Try "(" and ")" this might solve the problem.
Re: The way Outlook wrapped your code,

40tude_Dialog lets you marks lines you don't want wrapped.
My hyper-custom newsreader, X.EXE,
never automatically wraps anything... as a rule.
( all wrapping must be done manually )
I know it. Outlook express is not very good in sending code samples.
But right now I am very interested in trying another news reader, maybe if I
can find more time.
Very interesting... thanks. But as I said above,
only macros give me the flexibility/readability that I demand,
...I'm not so concerned about speed.
I am not going to discuss about macros or not, because everybody should use
the techniques that works best for them.
I tried macro's but I am coming back from them because I lose track what the
code does and hides bugs. It becomes too abstract for my taste.
 
The way I use whitespace is the most readable to me, of course,
and I expect you to change it to taste too.
Yes I understand. :-)
I also put my "{" at the end of the line of the if/for/... function.
This way I can seem more code and less white spaces, so I have one big
overview of my working of the function without need to scroll. It is a
matter of tast.
 
Hi Bikini_Pope, Re: My comment that
no one here produced anything half as good as my HTM_TXT.CPP code,

Ya told me: << Man, you really have created your own little fantasy here,
haven't you ? >>

Kelsey was the only one who even tried, and he trashed my home page,
falsely claimed that HTM_TXT.EXE didn't work ( refusing to provide proof ),
He also couldn't handle tags like .

So you tell me... who did a better job of it ?

You can read about those events here ( April_Fools day, no less ):
news:[email protected]
 
The way I use whitespace is the most readable to me, of course,
Yes I understand. :-)
I also put my "{" at the end of the line of the if/for/... function.
This way I can seem more code and less white spaces, so I have one big
overview of my working of the function without need to scroll. It is a
matter of tast.
There is one thing I do, if I have to touch someone leses code, is that I
try to keep the coding style as much as I can of the orignal person. But
normally I will go and ask this person to change his code himself is he is
available. If not I change, and send the changes, so when he has time to fix
it , he can send back the code and I overwrite my verison with the official
verison.
 
Hi Olaf, Re: Readability and whitespace preferences, You told me: <<
I also put my "{" at the end of the line of the if/for/... function.
This way I can seem more code and less white spaces, so I have
one big overview of my working of the function without need to scroll.
It is a matter of taste. >>

Wow... finally, some agreed with me about something... wonders never cease.
 
Hi Olaf, Re: Readability and whitespace preferences, You told me: <<
I also put my "{" at the end of the line of the if/for/... function.
This way I can seem more code and less white spaces, so I have
one big overview of my working of the function without need to scroll.
It is a matter of taste. >>

Wow... finally, some agreed with me about something... wonders never cease.
It is not that we are in discussion that I do not repect you. ;-)
I also listen and learn. You do have valid reasoning. And I see that you are
experienced and actually know what you say. :-)
 
From showing my code, for example my HTM_TXT.CPP,
which demos how my X.CPP converts HTML files into plain_text files:
http://www.Cotse.NET/users/jeffrelf/HTM_TXT.CPP

Hey - thats something Ive been looking for, hence why I took a look.
I found that no one here was willing to take the time to learn
my standard methods... which is totally understandable.

Standard methods? # defining common language constructs to something
that youre familiar with...yuk! Id hate to have to maintain a large
code base written by someone who did that....
But I also found that no one here could produce anything half as good.

Good? There are many people here who could produce something that
would produce the same results. Some might make something more
efficient, some might make something more maintainable, some might
make something with more functionality, some might make something more
portable, some might make something with fewer bugs....I personally
did NOT consider the code that I saw to be "good".
I think that's because the STL and C# make people lazy,
they tend to rely on the built-in stuff too much.

<chortle> We're ALL dependent on our libs these days (in whatever
shape or form they take) and have been for a loooooong time. In fact,
let me rewrite that statement for you:-

"I think that's because header files and C make people lazy, they tend
to rely on the built-in stuff too much."

Im prity sure I read/heard a similar statement by an asm programmer
back in...ooohhh '89.

Anywyas, laziness is the entire reason I program in C# these days
rather than C++ - I code faster and end up with fewer bugs. Sure Id
LIKE the portability and speed of C++ - fact of the matter is though
that its cheaper to throw more hardware at most projects than it is to
write effiecient code. In fact those are the exact reasons I moved
from Basic to C, to C++, to Java, to C# etc. It isnt JUST a matter of
speed.....

Anyways - I looked at your code and decided to stick to
strHTML = Regex.Replace(strHTML,@"(<[^>]+>)",string.Empty);

Regards
 
Back
Top