473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[LONG] C# too sharp for me

Man I've grown tired with C#/.NET the last three days I spent trying to
put a NULL value in a database. C# initializes all uninitialized
properties to 0 (for numeric types) and didn't have until C# 2 any
concept of NULLs. I keep wondering how you guys built all these .NET
apps on the top of a database. And guess what? If you fail to
initialize a DateTime (maybe because you just don't want to touch it!)
you get it infact initialized to {01/01/0001 0.00.00} but of course
when you try to put it in a SQLServer db you get this error in return:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and
12/31/9999 11:59:59 PM

Now in C# 2 you have the option to choose to declare something as a
Nullable... but it's just a hack (even if builtin the language) and
using Nullables prevents you from doing all sort of things, and strings
cannot be declared as Nullable but at least they are initialized
correctly if you don't touch them!

I understood just yesterday what's all the buzz around dynamic
languages since, even being a Python amateur, I still didn't get it
fully: I wanted to pass a property like Foo.Number as a parameter to a
method and I would have to use a delegate or an anonymous method
(another new feature... and, yeah, you cannot pass a property by ref
http://msdn2.microsoft.com/en-us/library/w86s7x04) which they tell you
that you can use it everywhere you would use a delegate but no, not
there, not where you need it the most or maybe with odd consequences.
Quoting from Jesse Liberty "Visual C# 2005 a Developer's Notebook"
published by O'Reilly:

<quote>
....what happens if I reference local variables in my anonymous block?
Good question. This can cause quite a bit of confusion and is a natural
trap to fall into, especially if you don't fully understand the
consequences.
C# allows local variables to be captured in the scope of the
anonymous code block, and then they are accessed when the code block
is executed. This can create some odd side effects, such as keeping
objects around after they might otherwise have been collected.
</quote>

Ok properties are not fields/variables but pardon me if I was looking
to implement yet another workaround to my problem.

And you now what: how about not knowing the type of a property you pass
to this function, well, you gotta use a generic (another new feature of
C#2)... and all this for doing somethinig that in Python and Ruby is
not even a problem... ah and did I tell you the best thing? ADO.NET
which is your only chance to talk to a database in the .NET managed
world doesn't support Nullable types: I found maybe by chance or
because, after all, god still loves me, a workaround since as Microsoft
confirmed there are no solutions, only workarounds if you want to pass
a NULL value to a SqlParameter. BTW I thought that using SqlClient you
would just bypass ADO.NET and talk directly to SqlServer if you didn't
mind tying you hands and foots to SqlServer. A guy had to write
Nullable types himself to use NULL values in C# v. 1
(http://nullabletypes.sourceforge.net/)

The only kinda dynamic feature of C# is Reflection which is another
way to say introspection which is one of those features I thought I
would never need even to learn in the C# "we give you everything out
of-the-box world" but actually comes handy in many places due to the
_limitations_ of the .NET platform.

Well, I'm done... this morning I bought a copy of Programming Ruby!

Arthur

Nov 17 '05
23 2295
<"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult
dot co dot uk>> wrote:
You can create synchonrized methods in C#.
Yes - it's not part of the actual language though, which was what I was
comparing. I should have made that clearer though.
I wouldn't recommend it as it
tends too lead to very coarse grained locking


Likewise.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #21
> In what way is C# *simpler* than Java? The way I see it, it's more
complicated than Java, as a language. If we consider Java 1.4 vs C# 1.0
(which is roughly fair, as would be Java 1.5 vs C# 2.0) then:


I not going to fight a Holy War, although I'm amused to have drawn such a
sharp response. By simpler, I mean easier to learn and use. Obviously, some
added features make a language easier, some have potential to make it harder.
(Is a car with an automatic choke simpler or more complicated than one with a
manual choke?) There is no point is differentiating between complexity in the
language per se and libraries; they are both in the mix. A lot of the
complication in Java is due to the desire for universality over machines and
cultures. So far, I've seen nothing in C# to rival the mysteries of
GridBagLayout, or LayoutManagers, in general. Nor has C# forced me to the
extremity shown below for formatting anumber. And I heard of a Java program
that was found to be spending 60% of its time creating new Gregorian
calendars....

As noted by someone else, you basically cheated on your list. Several of the
entries (properties, attributes, events,...) are things that are also easily
done in Java, perhaps under a different name.

I do find that delegates and events in C# are harder to understand (so far)
than the Listeners in Java. I may catch on eventually. I am amazed that there
isn't a properly defined DateBox control in C# (whine, whine, whine) that
implements a Windows standard date entry. (Data entry people HATE the
DateTimePicker. )

eye

class bcFormat{
DecimalFormat DF0d;
DecimalFormat DF1d;
DecimalFormat DF2d;
DecimalFormat DF3d;
DecimalFormat DF4d;

public bcFormat(){
Locale l = new Locale("en","US ");
//Locale l = new Locale("fr","FR ");
DecimalFormatSy mbols dfs = new DecimalFormatSy mbols(l);
DF0d = new DecimalFormat(" ###,###,###",df s);
DF1d = new DecimalFormat(" ###,###,###.0", dfs);
DF2d = new DecimalFormat(" ###,###,###.00" ,dfs);
DF3d = new DecimalFormat(" ###,###,###.000 ",dfs);
DF4d = new DecimalFormat(" ###,###,###.000 0",dfs);
}// end constructor
}// enc bcFormat

Nov 17 '05 #22

eye5600 wrote:
So far, I've seen nothing in C# to rival the mysteries of
GridBagLayout, or LayoutManagers, in general.


There's noting in Windows Forms with the functionality of GridBadLayout
either. If you want dynamic layouts you have to roll your own.

Nov 17 '05 #23
eye5600 <ey*****@discus sions.microsoft .com> wrote:
In what way is C# *simpler* than Java? The way I see it, it's more
complicated than Java, as a language. If we consider Java 1.4 vs C# 1.0
(which is roughly fair, as would be Java 1.5 vs C# 2.0) then:
I not going to fight a Holy War, although I'm amused to have drawn such a
sharp response.


I wouldn't say my response was sharp - just amazed, given how easy it
was for me to compile those two lists.
By simpler, I mean easier to learn and use. Obviously, some
added features make a language easier, some have potential to make it harder.
(Is a car with an automatic choke simpler or more complicated than one with a
manual choke?) There is no point is differentiating between complexity in the
language per se and libraries; they are both in the mix.
I'm afraid I disagree with pretty much all of this. To me, there's more
to learn in C#, therefore it's a less simple language. It's certainly a
joy to use, but I don't think it's simpler.

There's *definitely* a distinction to be drawn between language and
libraries - especially as in both cases multiple languages target the
same libraries. The design of the languages can be discussed entirely
separately from the design of the libraries.
A lot of the complication in Java is due to the desire for
universality over machines and cultures.
I'm not sure I'd agree with that. It has better support for
internationalis ation in some respects, and worse in others. Its
encoding support isn't nearly as well thought out as .NET's, but its
date/time handling, while more complex than .NET's (partly due to
having about three goes at it) is definitely better.

I really can't say I find Java complicated - and as a language, I still
believe it to be simpler than C# (pre-1.5, at least; generics bring a
whole different ball-game in there).
So far, I've seen nothing in C# to rival the mysteries of
GridBagLayout, or LayoutManagers, in general.
No, more's the pity. Fortunately, flexible layout management (which is
sorely missing, or at least underplayed)
Nor has C# forced me to the
extremity shown below for formatting anumber.
I can't say I've often had to use five different number formats varying
only by precision in the same program, personally...
And I heard of a Java program that was found to be spending 60% of
its time creating new Gregorian calendars....
Then someone wasn't being careful enough - it's very easy to avoid
that, in almost all situations. It's easy to fall into performance
traps on both platforms.
As noted by someone else, you basically cheated on your list. Several of the
entries (properties, attributes, events,...) are things that are also easily
done in Java, perhaps under a different name.
They're in no way part of the language though. Just because the pattern
can still be followed doesn't make them part of the language. Does C
have namespaces? No. You can follow a pattern of prefixing all function
calls with a namespace, but that's not the same as the language having
a namespace feature.
I do find that delegates and events in C# are harder to understand (so far)
than the Listeners in Java.
Interesting - I find exactly the reverse is true. I love C# events and
delegates. The biggest thing I miss in Java is the "using" statement,
to be honest. I very rarely need explicit try/finally blocks in C# :)
I may catch on eventually. I am amazed that there
isn't a properly defined DateBox control in C# (whine, whine, whine) that
implements a Windows standard date entry. (Data entry people HATE the
DateTimePicker. )


Not being a data entry person, it hasn't bothered me much. Most of what
I miss when writing C# is the excellence of Eclipse in terms of
navigation, refactoring and unit testing. Some of that will change,
with any luck with VS 2005. What won't change (at least for a while) is
C#'s lack of an equivalent to Java 1.5's enums which, while
occasionally a little rough around the edges, are incredibly handy.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
445
by: Vi | last post by:
Some of you might be interested in this open source AutoUpdater for ..NET "Sharp AutoUpdater provides an auto-update feature for .NET applications. Using XML configuration files, Sharp AutoUpdater component detects if there is a new version of the software, downloads, unzips, and installs the new files." Link: http://csautoupdater.sourceforge.net/
0
1520
by: application | last post by:
is it possible to create a simple com dll in c-sharp? i need to use a c-sharp com from an asp page( not aspx) and i read in google about regasm and csc and some other strage words but never find a full example of how to do it. Thanks
12
3429
by: strict9 | last post by:
Hello all, I'm writing several queries which need to do various string formating, including changing a phone number from (123) 456-7890. After some problem with data mismatches, I finally got it to work only to see that it takes 30-60 seconds to run the query, instead of the usual .5 seconds when I use a query without a function. Here is the code for the function. I call it using
12
20288
by: __frank__ | last post by:
Which format I have to use in scanf, to format a long long int (64bits int __int64 in MS VC++). Thanks in advance
4
2507
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got hard time to understand vb syntax. I don't know if anyone in here can point out which is the equivalent object used in c sharp. Translate these two lines to C sharp: Sub Next_Click(Sender As Object, e As EventArgs) Select Case...
2
3894
by: HishHish | last post by:
I have a Java code that I want to convert it to C-sharp in order to put it in my ASP.NET web application. I used the JLCA (Java Language Conversion Assistant) for conversion, but it gave me many errors indicating that there are not matches in .NET for those Java classes!! The Java code is: ***************************************************************** import java.util.Properties; import javax.mail.*;
5
1697
by: Alberto | last post by:
What sharp (from c sharp) stand for or where does it comes from? thank you
69
5569
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after assigning them their maximum defined values. However, the output of printf() for the long double 'ld' and the pointer of type void 'v_p', after initialisation don't seem to be right. The compiler used was gcc (mingw) with '-Wall', '-std=c99' and
22
591
by: Vijay | last post by:
With the option strict On set..... Dim fs As FileStream = File.OpenRead(strFile) With fs Dim buffer(fs.Length) As Byte ' <--- Option Strict On disallows implicit conversions from 'Long' to 'Integer'. ' other stuff.. End With
20
2613
by: windandwaves | last post by:
Hi Folk I am a PHP programmer, but I like to learn c-sharp as it seems to be in hot demand around here. My questions are: - how does c-sharp relate to PHP - do you like c-sharp and its cousins - are there better things to do then c-sharp? Thanks a million
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.