hate these ads?, log in or register to hide them
Page 131 of 132 FirstFirst ... 3181121128129130131132 LastLast
Results 2,601 to 2,620 of 2634

Thread: <xml><thread isTerrible="true" isUnderstandable="false" /></xml> - Coding help thread

  1. #2601

    Join Date
    May 31, 2011
    Posts
    6,553
    One thing I will never understand is that C and (apparently C++ too) hasn't automated memory management/garbage collection. I get it that "in the beginning" that wasn't a thing, but half a century later? I mean, unless you are a very experienced programmer, the compiler/runtime will always do a better job at it then a human.

  2. #2602
    Kerdrak's Avatar
    Join Date
    August 5, 2013
    Location
    Queens, NY
    Posts
    858
    Quote Originally Posted by Hel OWeen View Post
    One thing I will never understand is that C and (apparently C++ too) hasn't automated memory management/garbage collection. I get it that "in the beginning" that wasn't a thing, but half a century later? I mean, unless you are a very experienced programmer, the compiler/runtime will always do a better job at it then a human.
    C#

  3. #2603
    GeromeDoutrande's Avatar
    Join Date
    April 10, 2011
    Location
    Fakefrenchistan
    Posts
    4,001
    I think "evolving" programming languages would often cause more problems than benefits (I mean just look at C++ what even is this thing anymore). Better to just create a clean new language.

  4. #2604

    Join Date
    May 31, 2011
    Posts
    6,553
    Quote Originally Posted by Kerdrak View Post
    Quote Originally Posted by Hel OWeen View Post
    One thing I will never understand is that C and (apparently C++ too) hasn't automated memory management/garbage collection. I get it that "in the beginning" that wasn't a thing, but half a century later? I mean, unless you are a very experienced programmer, the compiler/runtime will always do a better job at it then a human.
    C#
    Which is quite new. Considering that BASIC has automated memory management/garbage collection since forever, it's strange that C insists on being "leacky".

    Also: C# is more of a Pascal derivat than a C one. And Pascal also has it since forever.

  5. #2605
    GeromeDoutrande's Avatar
    Join Date
    April 10, 2011
    Location
    Fakefrenchistan
    Posts
    4,001
    Specifically concerning C and garbage collection, I suppose C doesn't have it, because it is intended to be "the minimal overhead language". Whether that works in practice is up for grabs I guess, but there certainly are C libraries with a unique reputation for performance in scientific computing.

    I don't know why C++ doesn't have gc (I mean just look at C++ what even is this thing anymore).

  6. #2606

    Join Date
    April 16, 2011
    Posts
    274
    Quote Originally Posted by GeromeDoutrande View Post
    Specifically concerning C and garbage collection, I suppose C doesn't have it, because it is intended to be "the minimal overhead language". Whether that works in practice is up for grabs I guess, but there certainly are C libraries with a unique reputation for performance in scientific computing.

    I don't know why C++ doesn't have gc (I mean just look at C++ what even is this thing anymore).
    Predictability does not go well with a GC. Granted the automatic GC have improved a lot but in some settings they can still chose to "stop the world" at inconvenient times to clean up. The overhead of a GC can also be difficult to support in some small devices.

    I do C programming on an embedded realtime OS for a living and I would hate to having to consider a GC in that equation as well.

    So if you want near total control and predictability (and performance) then a GC is not the way to go but in many, many cases the drawbacks of a GC are outweighed by the many advantages.

    A newish option that can largely do the same as C and C++ just safer is the programming language Rust. It provides a number of compile-time guarantees such as no dangling pointers and multiple write access to variables etc. Check it out if you want to try something low level but hate all the foot guns in C and C++.

  7. #2607

    Join Date
    May 31, 2011
    Posts
    6,553
    Makes sense. I keep forgetting about all the embedded stuff.

  8. #2608

    Join Date
    April 9, 2011
    Posts
    400

    Post

    Quote Originally Posted by Hel OWeen View Post
    Makes sense. I keep forgetting about all the embedded stuff.
    Thats the entire domain of C

    C++ is mostly high performance computing these days, and there you also don't want garbage collection most of the time because of performance considerations.

  9. #2609
    Movember 2012 I Legionnaire's Avatar
    Join Date
    April 9, 2011
    Posts
    2,087
    You probably wouldn't appreciate GC kicking in while playing an FPS or something similar either

  10. #2610
    Movember '11 Best Facial Hair, Best 'Tache Movember 2011Movember 2012Donor helgur's Avatar
    Join Date
    April 24, 2011
    Location
    Putting owls in your Moss
    Posts
    10,502
    Quote Originally Posted by Hel OWeen View Post
    One thing I will never understand is that C and (apparently C++ too) hasn't automated memory management/garbage collection. I get it that "in the beginning" that wasn't a thing, but half a century later? I mean, unless you are a very experienced programmer, the compiler/runtime will always do a better job at it then a human.
    Libraries like Qt makes garbage collection and cleanup more managable. Just binding a QObject to a parent (that's deleted) cascades and cleans up anything that object is associated to in memory.

    https://stackoverflow.com/questions/...32239#19332239

    (yes I know it isn't strictly automated garbage collection but it still does help)
    Last edited by helgur; May 30 2021 at 08:22:11 PM.

  11. #2611
    Movember 2011Movember 2012 Nordstern's Avatar
    Join Date
    April 10, 2011
    Posts
    13,610
    "Holy shit, I ask you to stop being autistic and you debate what autistic is." - spasm
    Quote Originally Posted by Larkonis Trassler View Post
    WTF I hate white people now...
    Johns Hopkins CSSE COVID-19 Dashboard (updated link)

  12. #2612

    Join Date
    May 31, 2011
    Posts
    6,553
    HALP - PowerShell and XML

    I'm trying to modify an InstallShield script (*.ism) with PowerShell. These are XML files. Specifically I want to set the product version number of the software. In the UI, located in the Installation Information -> General Information section.
    This is the XML representation of it:
    Code:
    <table name="Property">
     <row>
    	<td>ARPNOMODIFY</td>
    	<td>1</td>
    	<td />
     </row>
     <row>
    	<td>ARPNOREMOVE</td>
    	<td>1</td>
    	<td />
     </row>
     <row>
    	<td>ARPURLINFOABOUT</td>
    	<td />
    	<td />
     </row>
     <!-- tons more of these /row nodes, before finally at the end we find this -->
     <row>
    	<td>ProductName</td>
    	<td>MyAwesomeApp</td>
    	<td />
     </row>
     <row>
    	<td>ProductVersion</td>
    	<td>1.2.3.0</td>
    	<td />
     </row>
    </table>
    In summary we're looking at/for
    Code:
    <table name="Property">
    	<row>
    	   <td>ProductVersion</td>
    	   <td>1.2.3.0</td>
    	   <td />
    	</row>
    </table>
    As you can see, there's no id/name to directly address the version number /td node. So I iterate thru the nodes and look for "ProductVersion", knowing the next /td node is where I need to change it. So far, so good - that works.

    But how do I change the value "1.2.3.0"?

    Code:
        # Load it into an XML object
        $xmlDoc = New-Object -TypeName XML
        $xmlDoc.Load($temp)
        # 
        # //msi/table[@name="Property"]/row/td[text()="ProductVersion"]
        [bool]$foundVersion = $False
        foreach ($xmlItem in (Select-XML -Xml $xmlDoc -XPath '//msi/table[@name="Property"]/row/td')) 
        {
            # The previos node was 'ProductVersion', this one is the actual version number then
            If ($foundVersion) {
                Write-Host " - (Before) xmlItem.ToString()" $xmlItem.ToString()
                $xmlItem = $versionSoftware
                Write-Host " -  (After) xmlItem.ToString()" $xmlItem.ToString()
                $foundVersion = $False
            }
            
            If ($xmlItem.ToString() -eq "ProductVersion") {
                Write-Host "- !!! Found it:" $xmlItem.ToString()
                $foundVersion = $True
            }
        }
    
        $xmlDoc.Save($temp)
    Here's the output of that snippet
    Code:
    - !!! Found it: ProductVersion
     - (Before) xmlItem.ToString() 1.2.3.0
     -  (After) xmlItem.ToString() 1.2.3.4
    However, although the time stamp of the file is updated, indicating a successful save, the version number hasn't changed. What am I overlooking here?
    Last edited by Hel OWeen; July 16 2021 at 04:47:21 PM.

  13. #2613
    Daneel Trevize's Avatar
    Join Date
    April 10, 2011
    Location
    T L A
    Posts
    13,015
    Is $versionSoftware declared as a String, rather than an XML element? You might need to modify $xmlItem.'#text' value instead of the whole object.

    You should also probably break out of the loop once the modification is done.
    Quote Originally Posted by QuackBot View Post
    Idk about that, and i'm fucking stupid.

  14. #2614

    Join Date
    May 31, 2011
    Posts
    6,553
    Quote Originally Posted by Daneel Trevize View Post
    Is $versionSoftware declared as a String, rather than an XML element? You might need to modify $xmlItem.'#text' value instead of the whole object.
    Yes it is declared as string. Will try the Text property tomorrow then. Makes sense.

    You should also probably break out of the loop once the modification is done.
    The real code has the Exit there, I just left it out of this reproducable example for clarity.

  15. #2615

    Join Date
    May 31, 2011
    Posts
    6,553
    Got it working, thx Daneel!

    For the sake of it, I also defined $xmlItem as XML though it does work without it*) and then was able to assign the version number to the .Node.InnerText property.
    Code:
    # These lines changed from the one I posted above
    # Added:
    [xml]$itemXml
    
    # Changed $xmlItem = $versionSoftware to ...
    $xmlItem.Node.InnerText = $versionSoftware
    *) which in turn made me also look up how to enforce variable declaration in PS, something I already actively try to do, but not consistently. E.g. I omitted it for the retrieved collection object $item in ForEach-Object {$item in $collection} loops.

  16. #2616

    Join Date
    May 31, 2011
    Posts
    6,553
    Has C# an equivalent for VB's integer division operator '\'?

    If both numbers are integers, that's easy enough because in that case a \ b is equal to a / b. But when dealing with (a) floating point number(s), VB does some "magic" behind the scenes:
    Before performing the division, Visual Basic attempts to convert any floating-point numeric expression to Long [That's Int64, Hel]. [...] The conversion to Long is also subject to banker's rounding.
    (Also: good luck including a standalone '\' in a Google search and hoping for meaningful search results...)

  17. #2617
    Daneel Trevize's Avatar
    Join Date
    April 10, 2011
    Location
    T L A
    Posts
    13,015
    Just specify the rounding before the division?

    Your variable's either already a float, or being implicitly cast. Your code won't compile if trying to convert a float to an int/long without a cast. Simply casting before the division might not use the rounding you desire.
    Last edited by Daneel Trevize; July 29 2021 at 03:54:17 PM.
    Quote Originally Posted by QuackBot View Post
    Idk about that, and i'm fucking stupid.

  18. #2618

    Join Date
    May 31, 2011
    Posts
    6,553
    I take this as a "No" to my question then, I guess.

    Thanks yet again, Daneel, for answering my beginner's questions, much appretiated!

  19. #2619
    Daneel Trevize's Avatar
    Join Date
    April 10, 2011
    Location
    T L A
    Posts
    13,015
    I don't remember any comparable operator, I would be surprised if it existed and I hadn't encountered it, but that doesn't mean it doesn't exist as standard or in an extension.
    Quote Originally Posted by QuackBot View Post
    Idk about that, and i'm fucking stupid.

  20. #2620

    Join Date
    May 31, 2011
    Posts
    6,553
    I dug a bit more after your answer and it seems that in fact C# doesn't have such an operator. It's OK, though. I'll do my own implementation - which was my plan in the first case, but I thought before reinventing the wheel out of ignorance, I'd better ask first.

Bookmarks

Bookmarks

Posting Permissions

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