What is the current preferred way to save user preferences in dotnet?

  • Thread starter Thread starter Mountain Bikn' Guy
  • Start date Start date
M

Mountain Bikn' Guy

What is the current preferred way to save user preferences in dotnet? Is the
registry the right place to do this? Can anyone recommend a good article (or
book) for this topic? Thanks.
 
Mountain Bikn' Guy said:
What is the current preferred way to save user preferences in dotnet? Is the
registry the right place to do this? Can anyone recommend a good article (or
book) for this topic? Thanks.

For a desktop app, save information in per-user registry keys, or in XML
files kept in per-user folders. I have some discussion about this in my
book, but frankly the documentation for the methods is fairly
straightforward. See the help on Application.UserAppDataPath and
Application.UserAppDataRegistry. Keep in mind that new folders and registry
keys will be generated for each version of your app that writes to these
locations, so you'll want to start managing your version numbers before you
start using these properties.
 
My preference is to define a class that holds them all and then serialize it
out to a file in the per-user directory
(Environment.GetFolderPath(SpecialFolder.Application) is the location).

That seems to work nicely.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Momento

Eric Gunnerson said:
My preference is to define a class that holds them all and then serialize it
out to a file in the per-user directory
(Environment.GetFolderPath(SpecialFolder.Application) is the location).

That seems to work nicely.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks. I'll get a copy of your book. It's one of the few C# books I don't
already have. I guess I just needed an excuse to get it and you just gave me
a good one. ;)

(Notice to authors: in exhange for really good and quick replies to my
posts, I'll purchase a copy of your book. How's that for a deal? ;)

However, in this case I think I'll use Eric's suggestion for saving user
preferences. (...I already have Eric's book. It's one of my favorites.)

Regards,
Mountain

P.S. The book I'm most excited about reading next is "Build Your Own .Net
Language and Compiler" by Edward G. Nilges, Josef Finsel
 
Mountain Bikn' Guy said:
Thanks. I'll get a copy of your book. It's one of the few C# books I don't
already have. I guess I just needed an excuse to get it and you just gave me
a good one. ;)

(Notice to authors: in exhange for really good and quick replies to my
posts, I'll purchase a copy of your book. How's that for a deal? ;)

However, in this case I think I'll use Eric's suggestion for saving user
preferences. (...I already have Eric's book. It's one of my favorites.)

Regards,
Mountain

P.S. The book I'm most excited about reading next is "Build Your Own .Net
Language and Compiler" by Edward G. Nilges, Josef Finsel

Josef had the idea and I am in his debt. He is a real nice guy who
already has some great books to his credit, and I urge you to look up
his work on Amazon, including The Reluctant Data Base Administrator's
Handbook. It is a book for a programmer who's been told by his manager
that he is now a DBA.

But Josef had to bail out of the actual writing of the book and I am
finishing it up for release early next year. I have written a compiler
for most of Quick Basic and spend the meat of the book in explaining
how that's done, using object oriented techniques, recursive descent,
and BNF.

I use Visual Basic and not C# to appeal to a wide audience.
 
Luckly I will download you're book from peer2peer networks and not buy it.
Phew, dont want to waste my money on some VB book.
 
Mountain Bikn' Guy said:

Sorry you feel that way. Here's my reasoning.

All or most C# programmers know Visual Basic, but not all Visual Basic
programmers know C#. Ergo I have a wider audience by using Visual
Basic.

C# allows more access to unmanaged facilities and features in general.
But, to show the basics of a compiler's front end, I need to Keep It
Simple and again accessible to programmers who use VB for the most
part.

You know, Brian Kernighan himself uses Visual Basic to teach Computer
Science 101 to non-majors, at Princeton University. He says he's
concerned to show America's best and brightest that programming is not
for dullards. Dave Hansen, also at Princeton, also opined to me that
doing a good job is more difficult using a language such as Cobol, the
VB of its day.

VB doesn't allow you to use pure pointers to point at void material,
invalid material, or the shimmering Moon: but this is a good thing.
There's no reason I can think of why a compiler would need untyped or
void data.

I will certainly concede that with Josef Finsel and with Dan Appleman
I decided in 2002 to use VB for the above reasons, and this was before
the move to C# at many shops in preference to VB.Net. I did not
foresee the popularity of C#, and, I can see its power at my current
"day job" where I use it.

I am in no mood to mount a typical, and profoundly narcissistic,
defense of Visual Basic, because over a career spanning thirty years,
I have heard too many rhodomontades, in defense of a programmer's
favorite language. I remain silent during these rhodomontades because
I abandoned the languages I started out with (1401 SPS and machine
language) as fast as I could...by debugging a nonworking Fortran
compiler in object code form. Since that time, I have programmed in
machine, several assemblers, Fortran,Cobol, Rexx, PL/I, True Basic,
Quick Basic, Visual Basic (3.. .Net), C#, C, C++, several special
purpose languages for the writing of scripts, and Spinoza, my own
language.

I have not found the language of the gods. This would be one in which
you did not need to write comments and in which clean compilation
would almost completely imply correct execution. Eiffel may be what I
am thinking about or object Spinoza.

My favorite language happens to be computer science and algorithms,
the common language of all programming languages.

Had Algol succeeded it might have become my favorite language, because
the designers of Algol were not in thrall to immediate corporate
needs, and because they foresaw (in their ideas about publication
languages) the need to couple the language to its presentation.

But, odds are you know VB, even if you dislike it. I can assure you
that the book will be free of excess respect for third party tools
which is characteristic of the VB community and shall instead stress
good algorithms which are uncharacteristic of the VB community. It
shall also be written in a witty and amusing fashion, also
uncharacteristic of the VB community.
 
But, odds are you know VB, even if you dislike it.

Knowing VB and wanting to read an entire book that uses nothing but VB will
limit its appeal, at least to me. I generally do not buy a book if it is
targeted to VB.
 
Hi Edward,

I still plan to buy your book, and I look forward to reading it. I am a bit
bummed that it uses VB and it sounds like a lot of other people here feel
the same way. I share Dave's habit of generally avoiding VB-targeted books.

You wrote a nice defense of your VB decision, but I can't help but thinking
that a C# focus didn't prevent Andrew Troelsen from becoming " #1 selling
author in the world on .NET" (http://www.otug.org/meeting/200205.html) and
winning numerous other #1 awards for C# and the .NET Platform.

My own guess (worth about 2 cents) is that a VB focus will hurt your book
sales more than help, in today's climate.

Anyway, I'm still going to purchase your book!

Regards,
Mountain
 
Dave said:
Knowing VB and wanting to read an entire book that uses nothing but VB will
limit its appeal, at least to me. I generally do not buy a book if it is
targeted to VB.

This book I hope will be an exception.

I could have written the compiler in C Sharp. I love bloody C Sharp.
But I agreed with Apress to write it in Visual Basic. Also, I would
like on behalf of the countless programmers who must use VB 24/7 to
show that advanced applications are possible in VB.

Too many headhunters diss good programmers merely because the
programmers use an unfashionable language.

It's programming's form of the rejection of a person from the South
based on his accent.

There is nothing natural about opening a block with a left curly
brace, and to older programmers, who may have trouble disambiguating a
left curly brace from a left parenthesis, the keywords of VB may be
clearer.

If mathematicians wasted half the time programmers waste on such
details: if mathematicians rejected the work of other mathematicians
*tout court* because the other mathematicians didn't use the
Politically Correct symbols, mathematical progress would slow to a
crawl.
 
Dave said:
Knowing VB and wanting to read an entire book that uses nothing but VB will
limit its appeal, at least to me. I generally do not buy a book if it is
targeted to VB.

In the 1970s, several books such as Fortran With Style came out and
sold, to the best of my knowledge, very well to Fortran programmers
ashamed of having to use languages that were already unfashionable.
Fortran With Style showed how programming with some dignity was
possible even if you had to use Fortran.

What I call programming with dignity is what PJ Plauger has called
Programming on Purpose, and my experience is that it is possible to
write undignified, offensive and foul code to no purpose in any
language: my kid found a C++ program that was written in this
fashionable and "advanced" language as a single main() procedure.

The authors of Fortran With Style made a discovery which I made
simultaneously, in 1974. This was that you did not have to use one of
the "structured" languages to write structured code. But the
widespread bad practice in languages like Fortran, Basic and Cobol
created the perception that the bad practice was caused by the
language.

But we know who to blame for bad practice and I am certain that this
includes programmers who haven't learned their trade but use a
fashionable language in which to wreak havoc. I am equally certain
that youse guys have learned your trade, in part because your favorite
languages teach good practice. I would agree that a programmer who
knows Basic only in all probability doesn't know his job (although one
of my students was a Basic-only programmer and knew his job).

I will review your comments with my publisher.

Power to the People,

Ed
 
I will review your comments with my publisher.
That's awesome!!! Maybe there is some (C#) hope after all!

If you minimize the VB and make the book a C# focused book, I"ll personally
buy 4 copies instead of 1.
 
Mountain Bikn' Guy said:
That's awesome!!! Maybe there is some (C#) hope after all!

If you minimize the VB and make the book a C# focused book, I"ll personally
buy 4 copies instead of 1.

Don't have any expectations in this area. The book was delayed by my
other committments, and until now I haven't had this type of feedback.
I am sure you can read Visual Basic.

Also, note that a large part of the book consists of a rich GUI that
shows in detail what a compiler does, and, VB is best for this.

I still have to crank a compiler for miniature Algol for the book.
Based on your comments, I will consider using C sharp.
 
Edward,
Thanks for your feedback. I'm looking forward to the book. I'll be happy to
proof read drafts and give you other feedback in any way that can be
helpful.
Regards,
Mountain

Edward G. Nilges said:
That's awesome!!! Maybe there is some (C#) hope after all!

If you minimize the VB and make the book a C# focused book, I"ll personally
buy 4 copies instead of 1.

Don't have any expectations in this area. The book was delayed by my
other committments, and until now I haven't had this type of feedback.
I am sure you can read Visual Basic.

Also, note that a large part of the book consists of a rich GUI that
shows in detail what a compiler does, and, VB is best for this.

I still have to crank a compiler for miniature Algol for the book.
Based on your comments, I will consider using C sharp.[/QUOTE]
 
Also, note that a large part of the book consists of a rich GUI that
shows in detail what a compiler does, and, VB is best for this.


Just out of curiousity, why do you say that Visual Basic is best for this?
 
Edward G. Nilges said:
That's awesome!!! Maybe there is some (C#) hope after all!

If you minimize the VB and make the book a C# focused book, I"ll personally
buy 4 copies instead of 1.

Don't have any expectations in this area.[/QUOTE]

Please use C#. I was very excited when I first heard
about the book, but now I find out that it's not C#
focused! Sorry, I can't buy it :(

Maybe Alvin Bruney has the right idea...
 
Back
Top