473,698 Members | 2,943 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
"Bill Butler" <qw****@asdf.co m> wrote:
Stop for a second and listen to his point, because it is valid.
If AGE is an optional DB field, then you may not have a value
to initialize it with. You can pick some DEFAULT age to stand
for the case of no age entered, but that is EXACTLY the age
== 0 thing.


True, but if that's a problem for his SQL Server app, he should be
using System.Data.Sql Types.

P.
Nov 17 '05 #11
Mr. McGinty,

As is often the case with computer snafu's, you are confusing one thing with
another, an easy type of mistake to make when using one thing to display
another thing which is a copy of a third, i.e. using a DateTimePicker to
display a value in your program which is a copy of a database value. You had
the misfortune of using the DateTimePicker which is a) ideosyncratic, and b)
flawed. The ideosyncracy is that it does not handle null values, so while it
is easy to insert a null into a database, it is impossible to use a stock
version of the DateTimePicker to do so. The DateTimePicker also misbehaves if
there is a null in your datatable; perhaps even if the field is merely
nullable.

I've described C# in the past as a simplified Java, which I think is fair
within the limits of a two word description. Many of the differences between
C# and, say, C++ are designed to avoid common mistakes made by non-experts.
This includes requiring variable declarations, initializing all variables,
not using (explicit) pointers, etc.

eye
Nov 17 '05 #12
eye5600 <ey*****@discus sions.microsoft .com> wrote:

<snip>
I've described C# in the past as a simplified Java, which I think is fair
within the limits of a two word description.


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:

Things in Java but not in C#:
1) Inner/nested classes
2) Checked exceptions
3) Synchronized methods

Things in C# but not Java:
1) Properties
2) Events
3) Delegates
4) Explicit interface implementation
5) Marking of methods as override/new
6) Attributes
7) Enums
8) User-defined value types
9) Indexers
10) Pre-processor directives
11) Boxing and unboxing
12) out/ref parameters
13) Parameter arrays
14) Operator overloading
15) The "as" operator
16) Switching on strings
17) foreach
18) checked/unchecked contexts
19) Unsafe code/pointers
20) The "using" statement

I may well have missed things on both lists, but I don't think I've
missed nearly enough to make C# a "simplified " Java.

--
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 #13

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
eye5600 <ey*****@discus sions.microsoft .com> wrote:

<snip>
I've described C# in the past as a simplified Java, which I think is fair
within the limits of a two word description.
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:

Things in Java but not in C#:
1) Inner/nested classes
2) Checked exceptions
3) Synchronized methods

Things in C# but not Java:


It's been a while, but I think I've done all these in Java:
1) Properties
2) Events
3) Delegates
4) Explicit interface implementation
5) Marking of methods as override/new
7) Enums
8) User-defined value types
9) Indexers
12) out/ref parameters
16) Switching on strings
I actually have a couple classes I can copy into J++,J# or c# and recompile
with almost no changes (none if I recall correctly).


I may well have missed things on both lists, but I don't think I've
missed nearly enough to make C# a "simplified " Java.

--
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 #14
Unfortunately, C# mostly gives the appearance of preventing mistakes.
It's still possible to leak memory, access disposed objects, lose
resources like file handles, but unlike C++ it's harder to spot the
offending code.

Nov 17 '05 #15
Entirely true: in C++ it's much easier to spot the offending code,
because it's all over the frickin' place. Memory leaks are the #1
bugbear of C++ programming. While you are correct that it's possible to
effectively leak memory in a C# application, it's not nearly as common.

Nov 17 '05 #16
Chance Hopkins <ch************ @hotmail.com> wrote:
Things in Java but not in C#:
1) Inner/nested classes
2) Checked exceptions
3) Synchronized methods

Things in C# but not Java:


It's been a while, but I think I've done all these in Java:
1) Properties
2) Events
3) Delegates
4) Explicit interface implementation
5) Marking of methods as override/new
7) Enums
8) User-defined value types
9) Indexers
12) out/ref parameters
16) Switching on strings


I actually have a couple classes I can copy into J++,J# or c# and recompile
with almost no changes (none if I recall correctly).


Trust me, you haven't. Java 1.5 has enums (which you can switch on),
the @Override attribute (which isn't mandatory, and there's no
"opposite" to shadow a virtuial method). It doesn't have any of the
rest (in the language - there are method naming conventions for
properties, but that's not part of the language itself).

--
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 #17
joe
"Bruce Wood" <br*******@cana da.com> writes:
Entirely true: in C++ it's much easier to spot the offending code,
because it's all over the frickin' place. Memory leaks are the #1
bugbear of C++ programming. While you are correct that it's possible
to effectively leak memory in a C# application, it's not nearly as
common.


What's the source of these comments? It might have been true that C++
was more prone to memory leaks than C# since it first came out
(modulo when C# first came out). The C++ standard was a moving target
for some years, so many programmers continued to use C++ as a "better
C", which meant doing their own allocations of C strings, using stdio
functions that should have been at least deprecated by now, etc.

Current compilers which implement the standard C++ library are much
less prone to memory problems, because the standard library takes care
or most allocations that are needed for a "typical" app (whatever that
is). If programmers continue to write C idioms for memory access
and get them wrong, that's hardly the language's fault.

C# does have advantages other than the fact that it came along after
most of the problems you mention were effectively solved. I'm still
learning it, so I might regret my comments here later, but at the
moment it strikes me that the .NET stuff is pretty well thought out
and easy to use. I don't know how much of that is due to the fact that
it's so much like Java, but I don't care at the moment, I'm just
trying to learn it.

Joe
--
Gort, klatu barada nikto
Nov 17 '05 #18
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
eye5600 <ey*****@discus sions.microsoft .com> wrote:

<snip>
I've described C# in the past as a simplified Java, which I think is fair
within the limits of a two word description.


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:

Things in Java but not in C#:
1) Inner/nested classes
2) Checked exceptions
3) Synchronized methods

Things in C# but not Java:
1) Properties
2) Events
3) Delegates
4) Explicit interface implementation
5) Marking of methods as override/new
6) Attributes
7) Enums
8) User-defined value types
9) Indexers
10) Pre-processor directives
11) Boxing and unboxing
12) out/ref parameters
13) Parameter arrays
14) Operator overloading
15) The "as" operator
16) Switching on strings
17) foreach
18) checked/unchecked contexts
19) Unsafe code/pointers
20) The "using" statement

I may well have missed things on both lists, but I don't think I've
missed nearly enough to make C# a "simplified " Java.

--
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


You can create synchonrized methods in C#. I wouldn't recommend it as it
tends too lead to very coarse grained locking, but you can
[MethodImpl(Meth odImplOptions.S ynchronized)]
void Foo()
{
}

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk


Nov 17 '05 #19
You can shoot yourself in the foot whatever language you choose. I can
leak memory in Java very easily, just like I can leak memory in C#.

However, getting to the question of the user in the original post, was
that not the reason why Nullable types in .NET 2.0 were introduced?

I had a discussion once with one of the Gang of Four authors on C# and
Java. And he said to me its the eternal debate between features vs
libraries. Java is a simple language, but its complexity are the
libraries (eg Swing). Whereas C# as a language is more complex, but
the libraries are simpler (sometimes too simpleminded IMHO). Then as
we kept discussing things the answer was that there is no answer. Just
like how some people like coffee and other people like tea! Yet both
give you a jolt from the caffein.

Nov 17 '05 #20

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
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
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
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
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
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.