Page 2 of 2 FirstFirst 12
Results 41 to 55 of 55

Thread: Trying to understand Collections

  1. #41
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Trying to understand Collections

    Quote Originally Posted by Sitten Spynne View Post
    ...In short, just steer clear of XML. .NET has the best XML parsers in the world. But it's sort of like having the best asbestos insulation in the world.
    Why? I'll give you that MS doesn't have a good native JSON parser, but don't most OS's that support JSON also have XML parsers? Java and Javascript both seem to have one. MS has made XML super easy on their platform.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  2. #42

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Trying to understand Collections

    Quote Originally Posted by Sitten Spynne View Post
    Can you imagine why MS might've made such a hard bet on XML?
    Poppa smiles... I guess it's the same reason they called their product Visual BASIC, "Let's call it BASIC, everybody's heard of BASIC... Go with the name everyone knows... It kinda looks like BASIC who cares that Beginners are really gonna struggle. It'll make us rich" !

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  3. #43
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Trying to understand Collections

    Poppa,

    As someone who creates code he has to maintain himself I like to leverage the heck out of classes.

    They can do much more than simply hold data.
    They can contain methods and events that will make them even more useful and intuitive.
    For instance you can also add your data by modifying the 'New' constructor of the class.

    Code:
    Public Class clsName   
      Public Property First As String = ""
      Public Property Last As String = ""
    
      Public Sub New(Firstname as string, Lastname as string)
        First = Firstname
        Last = Lastname
      End Sub
    End Class
    In Use:
    Code:
      Dim myName As New clsName("Mickey","Mouse")
      Dim names As New List(Of Name) 
    
      Names.add(myName)
    
      ' Or add the content directly to the list without creating a separate variable.
    
      Names.Add(New clsName("Donald","Duck")
    So now there is nothing to remember about filling your class variable. You are prompted for your two strings when you initialize your class as an object.

    If you wanted to make the process even easier you could also create a class that inherits List(of clsName) and overload the Add() Method.
    so that it becomes even simpler.

    Code:
     
    Dim Names as new clsListOfNames
    
    Names.Add("Casey","Jones")
    
    MessageBox.Show(Names(0).First & " (World's best engineer) " Names(0).Last)
    If you know your list will always read and write the list to disk then perhaps you also add Open and Save methods to the class.

    So in use.
    Code:
     
    Dim Names as new clsListOfNames
    
    Names.Open("C:\UserNames.txt")
    '...
    MessageBox.Show(Names(4).First)
    Names(4).First = "Bob"
    '...
    Names.Save("C:\UserNames.txt")
    The point here is that the supporting classes go into a file in your project with a relevant title where you can easily find it later.
    If you build your classes well you may never have to open their source again.
    Last edited by Gruff; May 15th, 2016 at 08:32 PM.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  4. #44
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Trying to understand Collections

    Quote Originally Posted by Poppa Mintin View Post
    I get a bit annoyed though when JMc rips into my suggestions, if he's that bothered by my replies, he should answer the guy's question himself.
    For the record, if I see what I think is a bad answer then I'll say so because I don't want either the person giving or the person receiving the information to settle on something that is significantly suboptimal. As for why I wouldn't answer the original question, there may be any number of reasons. The three that come to mind off the bat are that I don't have the time it would take, that I don't know the best answer but I know a bad one when I see it and that I don;t think the question warranted asking in the first place.
    Quote Originally Posted by Poppa Mintin View Post
    It makes me think I'll stop trying to help.
    Rest assured, I've provided my share of bad answers over time and I've been admonished for them on occasion too. I either ignored the response, apologised if I could see my error or made my case if I thought I was right. Regardless, I didn't stake my self-worth on what that person may or may not have thought of me and look at me now, doing admonishing of my own.

    I know I don't come across as friendly on occasion. That's generally because I don't try to be, not because I try not to be. I'm not here to make friends but to convey information that I think will help people become better developers. With that in mind, there are times where I think a kick in the pants is exactly what people need because it will be quicker to come to mind the next time and help prevent them making similar mistakes.

    I actually received a PM from someone recently who said they resurrected an account that they hadn't used in years specifically to thank me for doing that with them. They were pissed off with me at the time but soon came to realise what I was getting at and strove to improve themselves as a developer and succeeded as a result. I didn't make them what they are but I had a hand in their making that of themselves and that's what I'm here for. If there are a few casualties along the way then, to be honest, I can live with that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #45

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Trying to understand Collections

    Quote Originally Posted by jmcilhinney View Post
    i know i don't come across as friendly on occasion. That's generally because i don't try to be, not because i try not to be. I'm not here to make friends but to convey information that i think will help people become better developers. With that in mind, there are times where i think a kick in the pants is exactly what people need because it will be quicker to come to mind the next time and help prevent them making similar mistakes.
    I've never complained about your apparent attitude, I respect your advice too much to do that. It's just that...

    Quote Originally Posted by jmcilhinney View Post
    for the record, if i see what i think is a bad answer then i'll say so because i don't want either the person giving or the person receiving the information to settle on something that is significantly suboptimal. As for why i wouldn't answer the original question, there may be any number of reasons. The three that come to mind off the bat are that i don't have the time it would take, that i don't know the best answer but i know a bad one when i see it and that I don't think the question warranted asking in the first place. (corrected the English in this quote... Sorry)
    ... ok, a question wasn't worth an answer, nobody else's bothered to answer it so I'll try to help out. I write what I'd do under the stated circumstance. It often seems to me that you in particular, looking through the threads, spot that Poppa's answered a question... "Let's see what crap he's written this time".
    I know this is a little paranoid, but that's how it comes across to me. I'd say because it is mainly you that jumps on my answer. My point is that if the original question was too infra dig to answer why is the answer worth bothering with?

    Quote Originally Posted by jmcilhinney View Post
    rest assured, i've provided my share of bad answers over time and i've been admonished for them on occasion too. I either ignored the response, apologised if i could see my error or made my case if i thought i was right. Regardless, i didn't stake my self-worth on what that person may or may not have thought of me and look at me now, doing admonishing of my own.
    I suggest that this is a case in point: -
    Quote Originally Posted by jmcilhinney View Post
    Quote Originally Posted by Poppa Mintin
    Try this:
    Add an invisible, unsorted ListBox.
    No. Never do that. That would be like using an invisible TextBox to store a String. The whole point of controls is to interact with the user. If there's no interaction then there should be no control. That rule might be broken for complex tasks that only a WebBrowser or RichTextBox can do but if all you want to do is store a list of items then just use an array or collection. If you use a ListBox, its Items property is a collection so why have the useless control attached?
    Quote Originally Posted by Sitten Spynne View Post

    You want a list of these? Make a list. No one uses Collection. I'm serious. And don't even think about ArrayList. If the year is 2003, that's fine. But it's 2016, and we've had 11 years to learn why Collection and ArrayList are bad ideas. If you want to argue with a million people, feel free.
    Yes, I'm referring to the post which launched a thousand posts...

    Ok I exaggerate...

    And just for the record, I haven't had time to look at the up-date I was working on since this thread started, I'm spending all my time with this.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  6. #46
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Trying to understand Collections

    I like to poke fun at JM because he can come across as grumpy sometimes but I've also had enough exchanges with him in Chit chat to know he really isn't. Mostly he's just curt (in the main forums at least), he says what needs to be said and nothing more. Also, he has the cuddliest avatar in the whole of VBF

    I do know what you mean about feeling put upon when someone corrects you on the forum though. When we post on here we put our egos on the line. None of us knows everything and, whether we're asking a question, providing help or just getting involved in a discussion, we stand the risk of exposing our own ignorance. That's quite daunting. Seriously, I've led teams of professional developers and I'm constantly exasperated at how difficult it is to get them to post on a forum for exactly this reason. They'd rather spend hours throwing random configurations at some undocumented bug than just ask a question and get an answer.

    The trick, I think, is just not to get too precious about it. Remember that none of us know everything. We're all ignorant of something and we'll all get corrected from time to time. But the absolute worst thing you could do, for yourself and for the rest of us, is to stop contributing. Even when you get it wrong you add value because you provide something to correct.

    On the file format issue, I'd argue for CSV every time when my data is flat. It's easy to read and a highly efficient format for a computer to cope with. When my data's hierarchical the choice between xml and json really comes down to whether efficiency is more important to me than expliciteness (is that a word) and readability. Json is more efficient but xml is more explicit and readable IMO. I don't worry too much about the parsers because I known there's decent ones for either format. Also, the transformation and policing provided by xslt and xsd can be a huge boon for XML which Json lacks.

    On SOAP vs REST, again, I think it depends. SOAP is definitely heavier but it also comes with a whole load of stuff built in. The most obvious thing is a robust security framework.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  7. #47

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Trying to understand Collections

    Quote Originally Posted by FunkyDexter View Post
    Also, he has the cuddliest avatar in the whole of VBF
    Poppa smiles...

    Mine's made of wood!

    I wondered what language 'IMO' was for a moment.
    I'd've recognised 'IMHO' because that's the more common in the UK, I don't use text-speak, not only because I'm not lazy, nor am I trying to keep below a SMS 'Page Stage' but because I'm quite likely to get it wrong!



    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  8. #48

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Trying to understand Collections

    Quote Originally Posted by FunkyDexter View Post
    Also, he has the cuddliest avatar in the whole of VBF
    Poppa smiles...

    Mine's made of wood!

    I wondered what language 'IMO' was for a moment.
    I'd've recognised 'IMHO' because that's the more common in the UK, I don't use text-speak, not only because I'm not lazy, nor am I trying to keep below a SMS 'Page Stage' but because I'm quite likely to get it wrong!



    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  9. #49
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Trying to understand Collections

    "IMO" is used by the Goth compiler... It's the language of the Dark Web.

    -tg






    *pulls tongue out of cheek*
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #50
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Trying to understand Collections

    I can't use IMHO. My O has never been H
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  11. #51
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Trying to understand Collections

    Quote Originally Posted by Poppa Mintin View Post
    I suggest that this is a case in point: -



    Yes, I'm referring to the post which launched a thousand posts...
    You'll notice that I said to use a "collection" and Sitten Spynne said that noone uses a "Collection". We're both 100% right. I was using the general term while SS was referring to a specific type. The Microsoft.VisualBasic.Collection class is a holdover from VB6 and noone should ever use it unless they are upgrading VB6 code that already uses a VB6 Collection.

    In .NET, a "collection" is literally any type that implements the ICollection interface. That means that arrays are collections, an ArrayList is a collection, a List(Of T) is a collection, as is a Queue, a Queue(Of T), a Hashtable, a Dictionary(Of TKey, TResult), etc, etc. A collection is simply a way you collect multiple objects of the same type together. As I said, the Items property of a ListBox is a collection so if you were using a "hidden" ListBox you were actually already using a collection via that property but you had a useless control weighing it down.

    So as to help you avoid misinterpreting what I post like this again, please note that I ALWAYS use correct casing for type names and the like. If I post "collection" then I'm definitely not referring to a type because I would always begin a type name with the upper-case letter that it deserves.
    Last edited by jmcilhinney; May 16th, 2016 at 06:49 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #52
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Trying to understand Collections

    Quote Originally Posted by dbasnett View Post
    Why? I'll give you that MS doesn't have a good native JSON parser, but don't most OS's that support JSON also have XML parsers? Java and Javascript both seem to have one. MS has made XML super easy on their platform.
    This could turn into a thread. In outline form:
    • XML is good enough I won't push for a program that already uses it to switch, but if I'm starting from scratch I prefer JSON.
    • Some of this is because XML is very verbose: in general 25-50% of an XML file is end tags, equal signs, indentation, and other bits of syntax that make my customers with spotty 3G and expensive data plans very sad.
    • XML gives the user a little too much freedom. For any given class hierarchy, there are a number of different ways to represent the class that grows exponentially with the number of properties. Think: Is this property an attribute? An element? Does it use CDATA? etc. For any object, there is exactly one JSON representation.
    • The moment a customer's XML starts using a redefined default namespace, or namespaces at all, the complexity of your XML parser goes up by an order of magnitude. I don't know what the heck MS was thinking in any of their parsers' implementations of namespaces.
    • Parsing XML is very heavyweight: either you have to write a state machine for a SAX parser, or you have to pay the memory costs of the DOM parser. If going from JSON->Objects is a 1x memory hit. Going from XML->DOM->Objects is at least 2x.
    • XML parsers exist for every language, but support varies. I've used parsers in Python, Ruby, Perl, and LabVIEW, and what bugs me is for each language I have to learn a new set of parsers. JSON parsers, in general, consist of the same two methods on every platform and in every language.

    Really it comes down to: I can think of good arguments to use JSON over XML, but not many to use XML over JSON. So I reach for JSON when I can.

    There's a discussion about validation where JSON falls flat. There's some people who wanted to make a JSON schema specification, but it didn't grow legs. Most people agree if they want very strong validation as part of their text format, they'll use XML and either DTDs or schemas. I don't tend to use formats that need/use schemas, so JSON's adequate enough for me.

    With respect to JMC's post:

    "Collection" both the type and the word were very unfortunate choices spawned of the same "Microsoft does things different for the sake of doing things different" attitude I complained about above. What pre-.NET VB called a 'collection', everyone else called a 'property pag', or "associative array", or "hashtable", or "dictionary". I'm not aware of any other language calling that a Collection.

    Given the number of concepts VB intentionally names differently than other languages/Computer Science as a whole, I'm getting the feeling MS intentionally created this cognitive dissonance. If VB developers 'grow up' learning a different name for things, it makes other languages seem all the more confusing. That makes them less likely to try or stick with new languages. And that guarantees more developers who only buy MS tools.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  13. #53
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Trying to understand Collections

    I'm getting the feeling MS intentionally created this cognitive dissonance
    I'd stop short of that but I do think there was a large dollop of hubris. "We know best and surely the rest of the software world will eventually come to recognise that. And if they don't... stuff 'em"

    MS was the biggest player in the park for a loooong time but they weren't the smartest. Issues like this are the fallout of that.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  14. #54
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Trying to understand Collections

    I think one thing that may be getting forgotten in this talk about naming is that VB was specifically supposed to be the programming language for non-programmers so if things are done a bit differently in VB than the rest of computer science then it comes as no surprise to me.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #55
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Trying to understand Collections

    It may be the case that JSON is better in every possible way, but there is no doubt that there is a lot of data that is available publicly that is XML, though some of it not so friendly. Maybe the reason for that is because Microsoft was (is?) so dominant for so long. If Microsoft produced a decent .Net JSON implementation I would be more inclined to use it as opposed to XML.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width