c# is a good way to learn c

  • Thread starter Thread starter Montrose...
  • Start date Start date
Tom said:
Fast code that doesn't work is pretty much usless.

C'mon...let's not be sophomoric.

If Relf can write code that is faster than the built in Regex object in
..NET and Microsoft is offering the .Net system as an alternative to
c/c++ programming...then the whole exercise is ridiculous.

It condemns all code written in c# to being substandard.

How can I create a production site or app that uses Regex if I can't be
guaranteed of fast text search?

And why should I trust any assembly? Do I have to vet each and every
one of them to make sure that they do not have defects or faults?

At least I can see the source to know what text search algorithm they're
using in mono, but I can't even do that in .Net!
 
Jeff_Relf said:
or any other of the staggeringly bad C++ code in your example.
Frankly, the only time I've ever seen worse C coding
is in the Obfuscated C contests, and they're trying to write bad code,
not proclaiming it as good code.
One of my developers writes uncommented spaghetti crap like that
and I'd fire them on the spot. >>

Loop() is great shorthand, much better than for(;;) or whatever it is you use.

Jeff,

You're certainly winning this debate in my estimation.

The bottom line, after experimenting with Regex, is that the .Net
assemblies cannot be trusted -- as is.

What is .NET really about? It's really a business relationship.
Microsoft must provide the trust that a person can use the .Net
assemblies and convert to c# and still get all the speed that would be
part of a lower level language.

And if they can't -- then I see no reason to convert! For example, how
can I possibly trust their "automatic garbage collection" -- how do I
know if it's doing the job?

Show us the facts!
 
Sean Hederman said:
So by that argument a programming language is as old as it's most recent
incarnation? Okay.

A programming language is as old as its first version and as modern as its most recent incarnation.
 
In comp.os.linux.advocacy, Tukla Ratte
<[email protected]>
wrote
It won't be any time soon, though. After all, COBOL is still being used
for a lot of new development, and Java is getting to be just as embedded.

We'll see. The MONO project might surprise all of us. :-)

Microsoft -- because they probably want everyone to use Winforms
and other such proprietarianism.

Javadvocates -- because it's not Java. ;-)

Personally, I've not toyed with it so can't say, but Gtk# looks
mildly interesting. (There's also a Qt#.)
 
Hello Olaf,

Olaf Baeyens said:
I did look a C# generated assembler code, and I am not refering to ILASM but
to the real processor dependend assembler code and I am still very suprised
to see how nice the C# code gets converted to the raw processor power code.
It is really near C++ code. Any slowdowns is mostly related to using some
library functions or bad programming. Ofcourse using Interop and using
properties ans stuff, it also slows down, but so would C++ if you use
properties.

Why would properties cause slowdowns?

As I understand it, a property is just a function call which can be inlined in most cases and usually completely optimized away.
That, of course, depends on the quality of the compiler/optimizer but MS has some experience in that area.
No one can predict the future.

But one can prepare for it.

The top C++ developers are already adapting their habits to C++0x by using the boost libraries and keeping track of WG21 proceedings.
 
Olaf Baeyens said:
The C# way maybe not but if I remember the properties in C++ the methods
must be virtual.

C++ virtual method calls can be inlined when called directly (not via a base ptr or reference).
 
So, you are saying that if someone can write a faster regex process
than .Net, then .Net is worthless. That sounds a bit overdramatic.
Like saying if you don't drive the fastest car you should stay at home
until you starve.

You can write a production site that is does not have the fastest regex
process, if it can be delivered on-time and meets the performance
requirements. If the assembly is to slow to meet requirements then you
make adjustments. That is why we test early.

I don't understand this rampant black and white perception of these
issues. As an engineer, I feel it is my job to use whatever technology
I can to best accomplish the task. One of the most critical
requirements everywhere I have worked is maintainability of code. Can
someone else, of lesser skill and experience than you, add to your work
without having to pour over it for weeks or completely rework vast
sections of code? Language selection is influenced greatly by this
issue. How much will it cost to bring on a new person and get them
productive?

-Dan
 
HEY! I wanted to commented on that. :-)
Ik just installed C# on my new computer and now you gave the sollutions :
string name = "Alt.OS.Windows-XP, Comp.OS.Linux.Advocacy";
Console.Write(name.ToLower());

This would be he complete code:
---------------------
using System;
namespace ConsoleApplication1
{
class Class1 {
[STAThread]
static void Main(string[] args) {
string name = "Alt.OS.Windows-XP, Comp.OS.Linux.Advocacy";
Console.Write(name.ToLower());
}
}
}
----------------------

The rest is already explained I believe.

But Jeff makes the mistake to keep C# comparing with C++ which have a
complete different way of thinking and technology.
C# doesn"t need macros's and in my opinion macros is making code even more
unreadable since it is very hard to deciper what it is supposed to do.
And in many cases, Macro's don't always make your code faster. One
dimensional macros maybe, but once a macro uses a macro in a macro, then you
have no idea where you en up.

If you need speed then you must create one monolythic function that does
this one operation.

Now for the swap thing: The macro could be written like this in C#

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

And when decoded in assembler by the JIT (the debug version) you get this:
(I reverse engineered so you can follow what the assembler is doing)
Because of the newsgroup post wrapping will occure so unwrap it manually in
notpad or so, it is really worth it.

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

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.

Now for the alternative way:
----
class Class1 {
static public int Swap_32(int iOriginal) {
return (((byte) iOriginal)) << 24 | ((byte) (iOriginal >> 8)) <<
16 | ((byte) (iOriginal >> 16)) << 8 | ((byte) (iOriginal >> 24));
}
[STAThread] static void Main(string[] args) {
int iOriginal=0x01234567;
iOriginal=Class1.Swap_32(iOriginal);
}
}
----

iOriginal=Class1.Swap_32(iOriginal);
translates to:

00000015 mov ecx,esi
00000017 call dword ptr ds:[009750E0h]
0000001d mov edi,eax
0000001f 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:
00000000 push ebp
00000001 mov ebp,esp
00000003 sub esp,8
00000006 push edi
00000007 push esi
00000008 mov esi,ecx
0000000a xor edi,edi
---
0000000c mov eax,esi
0000000e and eax,0FFh
00000013 shl eax,18h
00000016 mov edx,esi
00000018 sar edx,8
0000001b and edx,0FFh
00000021 shl edx,10h
00000024 or eax,edx
00000026 mov edx,esi
00000028 sar edx,10h
0000002b and edx,0FFh
00000031 shl edx,8
00000034 or eax,edx
00000036 mov edx,esi
00000038 sar edx,18h
0000003b and edx,0FFh
00000041 or eax,edx
00000043 mov edi,eax
---
00000045 jmp 00000047
00000047 mov eax,edi
00000049 pop esi
0000004a pop edi
0000004b mov esp,ebp
0000004d pop ebp
0000004e ret

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

Have some fun :-)
 
Hello Jeff,

Jeff_Relf said:
In Microsoft C++ 7.1, I use these macros for drawing lines:
#define mt( x, y ) MoveToEx( DC, x, y, 0 )
#define lt( x, y ) LineTo( DC, x, y )

This is not good C++. Never was, never will be.
It may or may not be good C.
And, while the higher level Tools found in C# don't apeal to me,
the lower level tools, like macros, are oddly Verboten .
LoopTo() and ER(), shown below, are the Tools I prefer,
but C# doesn't allow macros like that.
So how would you write this in C# ?
#define LOOP while ( 1 )
#define \
LoopTo( StopCond ) \
while ( Ch && ( Ch = ( uchar ) * ++ P \
, Ch2 = ( uchar ) P [ 1 ] \
, Ch ) \
&& ! ( StopCond ) )

Gaak!

What's wrong with templates and inline functions?
typedef char * LnP ; // The name LnP comes from a naming convention I use.

int rv ; // Although it's a global, rv is what I call a Super_Temp.

// ER() and er() are shorthand for Bigg_ER() and Small_er()

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

LnP LowerCaseNG ( LnP Mixed ) { static LnP B; static int Sz_B ;
rv = ER( 200, strlen ( Mixed ) + 1 );
if ( Sz_B != rv ) { free ( B ); B = ( LnP ) malloc( Sz_B = rv ); }
LnP P = Mixed, D = B - 1 ; int Ch = * P --, Ch2 = 0 ;
LoopTo ( 0 ) if ( Ch > 32 && Ch < 128 ) * ++ D = tolower ( Ch );
* ++ D = 0 ; return B ; }

main() {
printf( "%s"
, LowerCaseNG ( "Alt.OS.Windows-XP, Comp.OS.Linux.Advocacy" ); LOOP; }

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

This is terrible, unmaintainable code.
It may be accepted in comp.os.linux.advocacy (I wouldn't know, I don't frequent that group) but try posting it in comp.lang.c++.moderated and see the reaction it will evoke.
Re: My comment that I don't like the look of String, cout or the STL,

You told me: << Good one. Haven't laughed that hard for a while.
If someone told me some drek like that in an interview,
it'd be sayonara baby, call me when you're mature enough to actually solve
the problems that confront our customers at a reasonable price. >>

Nice delusion, but you're not my employer.

I don't know who your employer is but I would like mine to be so lenient.
Loop() is great shorthand, much better than for(;;) or whatever it is you use.

I only care about what makes my code more readable,

More readable to who?

Cute rewriting of C++ syntax is universally considered as bad practice.
Don't take my word for it, c.l.c++.m (see above) is a great resource - you have Stroustrup, Sutter, Alexandrescu and their peers actively participating in discussions there and offering ego-less advice.

Standards, conventions and idioms are good for a reason.
Any C and C++ programmer should recognize for(;;) at a glance.
 
And that people that are more realistic actually are more brave to user
How is that "brave"?
Daring to stick your real name on, what you say.
Some people here make a lot of noise but they hide behind a nick name.
 
Olaf said:
Daring to stick your real name on, what you say.
Some people here make a lot of noise but they hide behind a nick name.

Right, and like "Olaf Baeyens" is a real name...gimme a break!
 
Dan said:
So, you are saying that if someone can write a faster regex process
than .Net, then .Net is worthless. That sounds a bit overdramatic.
Like saying if you don't drive the fastest car you should stay at home
until you starve.

No...I'm saying I need to know the exact specifications of the built-in
Regex so that I can determine if I need to write my own.
You can write a production site that is does not have the fastest regex
process, if it can be delivered on-time and meets the performance
requirements. If the assembly is to slow to meet requirements then you
make adjustments. That is why we test early.

There are other factors like stability, reliability and so on.

All I'm saying is I need metrics so I can make my decision.

I guess I could blindly test each assembly method...
 
Back By Demand said:
C'mon...let's not be sophomoric.

I agree.
If Relf can write code that is faster than the built in Regex object in
.NET and Microsoft is offering the .Net system as an alternative to
c/c++ programming...then the whole exercise is ridiculous.

The question is, is Relf's code as flexible and full-featured as MS's?

Special-purpose code *should* be faster than a generic solution.
It condemns all code written in c# to being substandard.

I fail to follow your reasoning.

std::basic_string said:
How can I create a production site or app that uses Regex if I can't be
guaranteed of fast text search?

Have you heard about premature optimization?
If the regex search is not your bottleneck, you should not worry about its speed.
At least I can see the source to know what text search algorithm they're
using in mono, but I can't even do that in .Net!

Try http://www.aisto.com/roeder/dotnet
 
Alex said:
Hello Jeff,



This is not good C++. Never was, never will be.
It may or may not be good C.

Nope. It makes assumptions. For example that a valid DC is present
And, while the higher level Tools found in C# don't apeal to me,
the lower level tools, like macros, are oddly Verboten .
LoopTo() and ER(), shown below, are the Tools I prefer,
but C# doesn't allow macros like that.
So how would you write this in C# ?
#define LOOP while ( 1 )
#define \
LoopTo( StopCond ) \
while ( Ch && ( Ch = ( uchar ) * ++ P \
, Ch2 = ( uchar ) P [ 1 ] \
, Ch ) \
&& ! ( StopCond ) )

Gaak!

Welcome to te world of Relf garbage
What's wrong with templates and inline functions?


This is terrible, unmaintainable code.
It may be accepted in comp.os.linux.advocacy (I wouldn't know, I don't
frequent that group) but try posting it in comp.lang.c++.moderated and see
the reaction it will evoke.

Relf is a windows using retard who has chosen comp.os.linux.advocacy as his
playground, entertained by another win-retard, John Bailo
Both have nothing at all to do with linux
I don't know who your employer is but I would like mine to be so lenient.

He is unemployable
He lives on welfare checks and witholding payment for his kids
And is actually proud of being a social misfit

< snip >
 
begin said:
Right, and like "Olaf Baeyens" is a real name...gimme a break!

Leave it to JBailo to make the real stupid posts. Like this one
Did you notice from where Olaf posts? Could you perhaps imagine that they
have different names in Belgium?
No, I guess you can't. Way too stupid for that
 
In comp.os.linux.advocacy, Tukla Ratte
<[email protected]>
wrote


We'll see. The MONO project might surprise all of us. :-)

Microsoft -- because they probably want everyone to use Winforms
and other such proprietarianism.

Javadvocates -- because it's not Java. ;-)

Personally, I've not toyed with it so can't say, but Gtk# looks
mildly interesting. (There's also a Qt#.)

QT# is no longer in development. It is a dead project. I would like to
see someone pick it up though...
 
The bottom line, after experimenting with Regex, is that the .Net
assemblies cannot be trusted -- as is.
And you are the big expert in this?
Did you have this from first hand or from hear-say?
And if it is from hear-say were these people experts or newbies using C
techniques in the C# violating the way C# worked?
What is .NET really about? It's really a business relationship. Microsoft
must provide the trust that a person can use the .Net assemblies and
convert to c# and still get all the speed that would be part of a lower
level language.
Yes, and they do a pretty darn good job in my opinion if you look at the
assembly code created by the JIT in one of my previous posts.
And if they can't -- then I see no reason to convert! For example, how
can I possibly trust their "automatic garbage collection" -- how do I know
if it's doing the job?
How to you know that unmanaged C++ is doing its job at releasing the memory?
The same way, you run a program as long as possible and check the memory.
In the last 2 years I created a lot of C# programs, and some of them are
pretty complicated using OpenGL and rendering a complete 3D scene, so I have
object instances to multiple lists. And it simply works. Reliably!
Show us the facts!
It is under your nose but you don't see.
 
And that people that are more realistic actually are more brave to user
Right, and like "Olaf Baeyens" is a real name...gimme a break!
Ohhhh, why would that not be my real name? Curious. :-)
 
Back
Top