|
Complete Novas HERE
When I look at Wrap All the Primitive Types In Structs
This looks logical to me ?
That said it took me a little time to learn to use {get;set;} example below
so my question is this code structure a good design or as stated just a fancy new way to write your code
If this is considered a programming question sorry just delete the post. I try to follow the rules honest
I did read all the replies
namespace CRUDLibrary
{
public partial class frmCRUD : Form
{
public static string dbName = "Contacts.db";
private string result;
public string fn { get; set; }
public string ln { get; set; }
|
|
|
|
|
Just curious where did you manage to get that book. Everywhere I search for it says it is pre-order to be delivered by the end of next month.
- Leonardo
|
|
|
|
|
Leonardo Pessoa wrote: Just curious where did you manage to get that book.
I'm a card-carrying member of oreilly.com -- ebooks from hundreds of publishers (manning, no starch, ms press, O'Reilly, Wiley, Addison-Wesley, -- to many to name) with 70,000 books available.
Most of the time the ebook releases before the book even releases and it is available on oreilly.com
You can try it for 10 days at this link (Create Your Trial: O'Reilly[^])
Disclaimer: I have no connection with oreilly and that is not an affiliate link.
The access to all 70,000 books and X,XXX number of videos is unlimited. It's quite amazing.
FYI - I've been a member of Oreilly since 2002 (when it only cost $10/month). It finally went to $19.95 / month and when they converted my account to their new system they let me grandfather into the old price $19.95 / month, but I know it is quite a bit more expensive now. Something like $39.95 / month or so.
|
|
|
|
|
I'm kind of against the whole "make your code more readable...at the cost of performance and efficiency". Programmers of the future who cannot understand the context of the past (and therefore the code) are of little concern. It might be that, as an engineer, my first stance is that all newcomers must be educated (a little) and eventually they should learn to educate themselves (a lot).
It harkens back to the guilds...but, except for being exclusive, there wasn't very much else wrong with their educational system.
So if someone wants to break OOP, they should write their own language and let everyone else be. I'm just happy I don't have to remember if that string of bytes was an integer or a floating point value (and I use the wrong mnemonic for multiplication). If you don't like inheritance, don't use it.
|
|
|
|
|
I agree with your answer.
Here's a reply I said to someone else that is about developer discipline related to this topic:
You have much experience also and most likely that means you have developer discipline (do things right the first time so you don't shoot yourself in the foot later).
Developer discipline doesn't seem like it is being taught in modern times -- probably influenced by dynamic languages like JavaScript which also encourage people to "type" code (not design it and write it).
So, for this modern world i believe the movement is to "put the discipline in the code" so those who come after are "forced" to use it the way we have designed it. In the past, we would've read the legacy code and kept the parts that seem right.
Just as you said,
Juan Pablo Reyes Altamirano wrote: my first stance is that all newcomers must be educated (a little) and eventually they should learn to educate themselves (a lot).
Unfortunately, there seem to be people moving into Software Development that just think they can start typing and produce a program.
|
|
|
|
|
raddevus wrote: probably influenced by dynamic languages like JavaScript which also encourage people to "type" code (not design it and write it). I can't even remember how many of my sequential programs were born on a DIN A2 paper where I draw everything with pencil, moving coins to simulate the value of the states and then playing with the possible permutations of the transistions.
Specially when timing / synchronisation of different systems were needed.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I would not say it's a new concept, DDD introduced the concept of value objects a while back. Strong typing a value is how many implement value objects in C#.
The logical continuation for this concept should be:
1- Add validation, what is the specific range of value that are acceptable to your function. In your example, should you accept a speed of 62123.25?
2- Add units, is it always the same unit, or should you convert from different units?
3- Displacement, Angle, Speed are very vague, are we talking about vehicles on a public road? or a spacecraft? Maybe we should use VehicleSpeed instead?
4- Maybe VehicleSpeed should derive from a base Speed class so you don't repeat units and conversions all the time? But you could add validation of acceptable speed value for a vehicle?
And we're back to the good old OOP. Should you calculate the Displacement in the VehicleSpeed class? I don't think so, this should be composition, but the encapsulation of the speed value, it's units and validation into a class is definitely desirable.
It is a question of perspective. We tend to work with good enough, but if you want accuracy, I would debate that those are the things you NEED to do.
The reasons why most of us don't go the Value Object route are: That's a lot of work. It takes time, we're in a hurry, it makes code base bigger, some would say more complex (I disagree).
Is Primitive Obsession a code smell? I say YES! But are we willing and able to do everything that is required to REALLY fix it?
Christian
|
|
|
|
|
Very interesting points...and you should read that book, because that is exactly the angle the author is taking. Chapter 1 was very good, challenging and interesting and has definitely changed my mind on many things. I think using these ideas at the right time will make better code.
Just started chapter 2 and it is continuing to be interesting so this is a really great book bringing together a number of interesting ideas.
|
|
|
|
|
I'm sure there are some good points, and that many of my objections may be only because such simple examples are provided, but as presented it rubs me the wrong way. I'm sure the author isn't saying "do this all the time".
I am unlikely to create a single-field or -property class or struct without also adding Methods. At least a custom ToString. Or make it IComparable to itself. Then there is some actual benefit.
My experience hasn't needed such things, but I could see separate structs for OunceTroy and OunceAvoirdupois, for instance. Yet I would not want to see someone making a struct for each time zone (use DateTimeOffset for that).
Two thoughts:
0) It looks like it can lead to a form of Hungarian Notation, but one with compiler support and protection.
1) If not C#, maybe another language would use this type of thing to provide compile-time safety, but decompose such simple structures to the underlying primitive types for improved speed. Maybe at JIT time?
|
|
|
|
|
Edited: The original Subject here was 'The Day I Learned to Hate the BOM'. After considering the first response, I have modified it to reflect a more appropriate and less offensive title. I'm only explaining this to provide context for the first responder's grievance. (and strike tags are not allowed in the subject)
I've been importing text files for over 20 years and I thought I'd seen it all!...CSV lines enclosed in double-quotes, CSV fields with commas (not enclosed in double-quotes), implied decimal places, packed decimal format, subtotal lines, total lines, garbage lines, etc.
What I haven't seen before now are text files with byte order mark (BOM) characters that don't seem to do anything significant except to require dealing with. It's probably been an issue long before now, but 90% of the time, the files have a header row so it wouldn't have mattered.
For fun, or as an office joke, you can add BOM to your own text files by changing the Encoding in NotePad.
"Go forth into the source" - Neal Morse
"Hope is contagious"
modified 17-Sep-23 11:32am.
|
|
|
|
|
Is that the same day as you saw BOM for the first time?
What is wrong with BOM? That you don't want to see it at all? That for this specific file, it "isn't needed", because all it contains is 7-bit US-ASCII?
You may of course declare that "I handle 7-bit US-ASCII only, so don't disturb me with anything else - Unicode is not my business, even when the characters are limited to US-ASCII. Just bug off with anything else!"
Fair enough, but then the software you produce is not for me. Most likely not for very many people outside the English speaking world. You are most certainly expected to handle BOM and Unicode/UTF8 today. If you are handling CSV, your are supposed to understand that in major parts of the world, it is five comma three, not five point three.
For the other stuff you mention: Fair enough; that should be easy to handle. If you haven't yet discovered that there are lots of variations in CSV formats (e.g. they are certainly not always comma separated, like in cultures where the decimal separator is not the point), take a look at the import options in Excel: It has handled this stuff for at least 15 year - I'd guess a lot more. Accept reality as it is, not as if reality was a problem.
And so on. You are free to put up a sign at your door: "Warning: No non-American data is handled by our software!" Actually, I'd be happy to know in advance, rather than discovering after I have signed a contract.
|
|
|
|
|
Thanks for the reply and for allowing me to realize that I had mis-titled the thread. I understand that the word 'Hate' was inappropriate for a number of reasons, firstly because I despise that word, and secondly because of your point about reality.
In my defense, the 'problem' had already been dealt with, (code fixed, tested, compiled, tested, and deployed) for the two affected imports before I made that post. I was simply annoyed about spending that hour diagnosing and fixing something that I'd never seen before...weird characters trashing the first element in a csv.
Per your post, I had a few ways to deal with it, now having a crash course in BOM:
0: Tell the customer that they would have to change the encoding. (put up a sign) The customer gets these data files from other departments/systems. To change the encoding is would likely be a manual process. Not ideal at all.
1: Be aware that a text/csv file might have those three weird characters at the beginning of the file. If so, disregard the BOM and move on.
2: Go into full research mode and discover all that there is to know about BOM and how it might be needed for all of my non-US customers. (current/future === none)
I chose option 1. The reality is that I have to deal with it. The chances that I get a file from a US customer that is BOM encoded, and that does not have headers, and where the first element of the line is important have become realized. I didn't account for the BOM and got 'bitten'.
Anyhow, my customer is happy again. I've learned something new and improved my software.
One of my favorite things about this profession is the constant learning and improving.
"Go forth into the source" - Neal Morse
"Hope is contagious"
|
|
|
|
|
The only thing to hate is hate itself.
|
|
|
|
|
|
"UTF-8 BOM considered harmful."
I'm assuming you're talking about UTF-8. Including a BOM with UTF-8 is generally unnecessary and frowned upon in most cases.
I'll have to review my latest text file reader to see what I do with them -- one I wrote earlier this year would ignore a UTF-8 BOM if it was the first three bytes of a file.
In general, a file should have only one encoding, but there is no requirement for that to be the case. If a file switches between encoding, then I believe a suitable BOM must be used to indicate that. But good luck finding a reader which will honor such an abomination.
When this sort of thing is more likely to be a concern is when reading from a non-file-backed stream such as a socket -- but I would expect that other controls would be put in place to avoid confusion.
Now I need to go create a CSV file which is UTF-8, but with a UTF-16 Word document as one of its values... (muhahaha!)
|
|
|
|
|
Yes, I depended upon some code I was writing at jsfiddle.net and suddenly the entire sample code was gone. I had worked on this for a few days. Oy!! PaNIC!! PANIC!!!
Here's a snapshot of the fiddle that exists and doesn't exist[^].
You can see that JSFiddle is generating a snapshot of my original code (on the right).
But, how can I see the code, but it isn't there!?! PanIC! p-p-p-PANIC!!!!!
However, if you click the jsfiddle then the system attempts to load the editor and everything is blank. Here's the link to the fiddle[^] -- which is blank.
!!!!
If you compare the link to the image you can even see that it is referencing the 72gzs94v ID that is supposed to be the code.
The code exists and it doesn't...
Got Very Lucky
I was able to inspect the code from the original snapshot and copy out the code using FireFox web tools so I didn't lose code that I had worked on for quite some time.
I no longer trust jsfiddle (and yes, I was a fool for trusting it in the first place.)
Public Service Announcement
Trust no one! Always save backups!!
I now have a backup of the code on my local machine. Phew...
|
|
|
|
|
You're missing the version suffix on the path. As far as I can see, the last version you saved was #74:
Edit fiddle - JSFiddle - Code Playground[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So fantastic!!
that's one of the reason I post these crazy things to CP...because there are so many smart and helpful people here.
Absolutely amazing you noticed that!!!
I wonder why that it wouldn't load that from my JSFiddle.net account??
Thanks so much for reading my post and for your help.
I really appreciate it.
EDIT
And I should say this too. I logged into my account from another web browser and it still failed.
Then I logged in on another machine and it failed too.
Must be a crazy bug in the JSfiddle account plugin.
|
|
|
|
|
|
One of the great mysteries of the web:
Once you put something on it, it exists forever... somewhere.
Until of course you need it again, and then it no longer exists anywhere.
Both of these statements are true simultaneously, of course.
Software Zen: delete this;
|
|
|
|
|
It's like the old monkeys on typewriters story. Every document, image, etc is out there somewhere. It just hasn't been indexed yet.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Gary R. Wheeler wrote: Once you put something on it, it exists forever... somewhere.
Until some suit decides to delete it thinking that will boost their site's SERPs:
CNET Deletes Thousands of Old Articles to Game Google Search[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
JS fiddle is awesome. I use it on the regular, but if you're tinkering with server-side or isomorphic JS it's much, much safer to just run it via node directly on your machine. Even for really simple stuff, its command line interpreter will handle things perfectly. Just as long as you don't need a DOM or styles for your quick and dirty testing.
Jeremy Falcon
modified 3 days ago.
|
|
|
|
|
Attempting to set up User Isolation on a IIS FTP on Server2022 so I can test a FTP Client I wrote.
I was expecting it to create a new user directory under FTPRoot when I logged in.
No dice.
Found some documentation.
FTP User Isolation <userIsolation> | Microsoft Learn[^]
Then I found this chart. It actually uses SPECIFIC path that must exist or you get the error:
530 User cannot log in, home directory inaccessible.
Login failed.
ftp>
User Account Types Home Directory Syntax
Anonymous users %FtpRoot%\LocalUser\Public
Local Windows user accounts (Requires Basic authentication) %FtpRoot%\LocalUser%UserName%
Windows domain accounts (Requires Basic authentication) %FtpRoot%%UserDomain%%UserName%
IIS Manager or ASP.NET custom authentication user accounts %FtpRoot%\LocalUser%UserName%
See a snapshot of this chart[^].
The 3rd one was the one I needed. It is strictly incorrect.
If you were to expand those environment vars as they are you'd get: MyFtpRootCompanyDomainMyUserName
It is supposed to have directory separators between them.
Like this ==> MyFtpRoot\CompanyDomain\MyUserName
Filed under weird (and annoying / bad documentation).
|
|
|
|
|
I thought FTP died. Wasn't there a memorial service for it in the mid aughts?
*hides*
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
|
|
|
|
|