As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/

[Programming] Page overflow to new thread

11112141617101

Posts

  • gavindelgavindel The reason all your software is brokenRegistered User regular
    Comments are code that the parser and compiler can't verify for you, and therefore should be regarded with suspicion

    Now that I am playing Persona 3, I read that comment in Mitsuru's voice...

    Regarding code comments, the locality of reference makes a huge difference. Always really frustrating to find a small book of documentation 10 classes above where you needed an explanation.

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    edited August 2019
    There's three categories of comment.

    There's that stuff that is required because it is API documentation (thing Javadoc, Godoc, python docstrings, etc).

    Then there is what should be there because the code is confusing or otherwise warrants elaboration (ex. regex, intentional switch case fallthroughs, etc). Knowing when and where to write these is the trick to good commenting.

    Then finally there's comments that are there because people were brainwashed in college to think that any code that isn't completely saturated with comments is inherently bad. These folks tend to ignore important concerns, like how code and comments, even if great to start with, can quickly diverge if not carefully maintained. Comments that lie are far worse than no comment at all.

    Monkey Ball Warrior on
    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • InfidelInfidel Heretic Registered User regular
    If you have to explain your code with comments, fix your code. If you have to add a comment so I can read your switch statement, just fucking stop being cute and rewrite it.

    If you are leaving a breadcrumb about WEIRD BUSINESS RULES JUST GO WITH IT, please comment! Those are the only ones that have been valuable and saved our asses.

    OrokosPA.png
  • vamenvamen Registered User regular
    edited August 2019
    Ugh, I am SO CLOSE. I have ONE more thing to get working and I'm set. But it's kicking my ass. This is much harder than it should be.
    ...or I'm MAKING it way harder =p.

    I have a string of values from a datarow in my DB that I need to use to repopulate a listbox when it loads.
    Right now I have:
    Dim s As String = (survinfo.Rows(0)("condition"))

    Which works great if they have only selected one item but any more and the listbox shows nothing selected, even though the variable is still holding all of the values.
    I'm trying to figure out how to say "select all the things" instead of the Rows(0).I
    I did a few things like this to try and split it up:
    Dim condList = Split(survinfo.Rows(0)("condition"), ",")
    or
    Dim condList As String() = s.Split(New Char() {","c})

    And then I tried a ton of combinations to try and say "for each item in the loop, add that value to the listbox" ...which is I THINK is done like so: ddCondition.Items.Add.

    I've googled so much for this that every link when I try to google it in a new way is showing I've already visited it =p.

    This is my latest attempt that I was SO SURE was going to work:
    Dim s As String = (survinfo.Rows(0)("condition"))
    Dim condList As String() = s.Split(New Char() {","c})
    Dim word As String

    For Each word In condList
    ddCondition.Items.Add(word)
    Next


    Any suggestions? =)

    I really wish the listbox was smart enough that the variable having a value of "1,2,3" means to select value 1, 2, and 3 without having to do this voodoo.\


    EDIT - Oh crap, I realized I'm closer than I thought. I just saw that my listbox literally adds the value numbers at the end of the list now.

    q103tgblqi8l.jpg

    So THAT is what the Items.Add does. Maybe I just need to figure out how to say "select those values" instead of .Add. Not quite sure what that is since the available ones seem to only do singular:

    kmwxsqpq4hn3.jpg

    But I feel like I'm close!


    vamen on
  • Monkey Ball WarriorMonkey Ball Warrior A collection of mediocre hats Seattle, WARegistered User regular
    Not wrong. However, that thing about switch fallthroughs is more of a workaround for languages with the bad switch design where fallthrough is the default. Go, correctly, makes break the default, and you have to specifically fallthrough, in the rare cases where that is what you actually want to do.

    "I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
  • thatassemblyguythatassemblyguy Janitor of Technical Debt .Registered User regular
    Phyphor wrote: »
    The real danger is when the code changes but the comments don't so the comments are wrong

    This means the team has people that do not, and/or a culture that allows them to not, fully participate in the code-review process.

    To be honest, this same argument applies to 'self describing' code - The real danger, and it is more dangerous than comment rot, is that someone decides that variable_for_purpose_x can be leveraged forward to mean both purpose_x and newly added purpose_y, but the variable stays the same name leading to code that now no longer documents itself (happens a lot in the embedded space, or during bug fixes where there is a desire to make minimal changes to avoid triggering more-than-necessary lengthy retests).

    Code reviews y'all, participate!


    Personally, having been burned (and I am currently en fuego grande) by other's code that is inadequately, or not at all, commented under the guise of 'self documenting code', I'm a Comment Advocate. There's a reason why it is taught as best practice during training/schooling.

    Document/Comment intent even if you think it should be clear by the structuring of the code. Very often there is a massive gulf between should and is.

    Different industries will have different needs for commenting, but across the board a lot of the arguments against comments can be boiled down to simply, "I don't want to explain my code, you figure it out."

    Which is often a really bad tactic for everyone.

    Every time someone comes back to a piece of code that (at the time) everyone thought was very clear with variables and everything and thinks, "Oh snap, who wrote this? It's really difficult to.. ooh, it was me, I wrote that. Whelp time to figure out what I was thinking, and do a refactor."

    Those poor sustaining/field/customer engineers that have to pick-up and maintain the code for the life-cycle of the product? No comments is equivalent of saying to them, "Fuck you. Got mine." However, it often comes back to bite the development engineer in the ass because they get called in on the escalation when the field/sustaining team can't figure out the code in order to fix the bug.

  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    http://antirez.com/news/124 is, in my opinion, the definitive summary of types of comments and why you would or would not write each type.

    borb_sig.png
  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    @thatassemblyguy Agreed. There are times I have to go back and look at some of my old code. Fortunately, I've documented it well enough that I can figure out why I did what I did, even if it is a language I haven't used in many years. I may not remember exactly what the code does, but I've usually got a pretty good handle on why it does what it does.

  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    vamen wrote: »
    Ugh, I am SO CLOSE. I have ONE more thing to get working and I'm set. But it's kicking my ass. This is much harder than it should be.
    ...or I'm MAKING it way harder =p.

    I have a string of values from a datarow in my DB that I need to use to repopulate a listbox when it loads.
    Right now I have:
    Dim s As String = (survinfo.Rows(0)("condition"))

    Which works great if they have only selected one item but any more and the listbox shows nothing selected, even though the variable is still holding all of the values.
    I'm trying to figure out how to say "select all the things" instead of the Rows(0).I
    I did a few things like this to try and split it up:
    Dim condList = Split(survinfo.Rows(0)("condition"), ",")
    or
    Dim condList As String() = s.Split(New Char() {","c})

    And then I tried a ton of combinations to try and say "for each item in the loop, add that value to the listbox" ...which is I THINK is done like so: ddCondition.Items.Add.

    I've googled so much for this that every link when I try to google it in a new way is showing I've already visited it =p.

    This is my latest attempt that I was SO SURE was going to work:
    Dim s As String = (survinfo.Rows(0)("condition"))
    Dim condList As String() = s.Split(New Char() {","c})
    Dim word As String

    For Each word In condList
    ddCondition.Items.Add(word)
    Next


    Any suggestions? =)

    I really wish the listbox was smart enough that the variable having a value of "1,2,3" means to select value 1, 2, and 3 without having to do this voodoo.\


    EDIT - Oh crap, I realized I'm closer than I thought. I just saw that my listbox literally adds the value numbers at the end of the list now.

    q103tgblqi8l.jpg

    So THAT is what the Items.Add does. Maybe I just need to figure out how to say "select those values" instead of .Add. Not quite sure what that is since the available ones seem to only do singular:

    kmwxsqpq4hn3.jpg

    But I feel like I'm close!


    I'm not ignoring you, I just haven't had a chance to sit and analyze this to the point where I might be able to offer advice. I'll get back with you as soon as I have a free moment.

  • EchoEcho ski-bap ba-dapModerator mod
    On the subject of code reviews and coding style, I'm going to give some feedback to a junior dev about this stuff. I saw a bunch of code where it went
    if blah {
    	doStuff()
    	return
    } else if blerp {
    	otherStuff()
    	return
    } else {
    	finalStuff()
    }
    

    The else statements are redundant there, and of course it was more code than that, so it ended up really dense and hard to follow. Getting rid of the else gives us more distinct blocks of logic and is generally way easier to follow, and gets rid of the indentation of the final logic. I'm always a fan of avoiding indenting deeper than required.
    if blah {
    	doStuff()
    	return
    }
    
    if blerp {
    	otherStuff()
    	return
    }
    
    finalStuff()
    

  • thatassemblyguythatassemblyguy Janitor of Technical Debt .Registered User regular
    Echo wrote: »
    On the subject of code reviews and coding style, I'm going to give some feedback to a junior dev about this stuff. I saw a bunch of code where it went
    if blah {
        doStuff()
        return
    } else if blerp {
        otherStuff()
        return
    } else {
        finalStuff()
    }
    

    The else statements are redundant there, and of course it was more code than that, so it ended up really dense and hard to follow. Getting rid of the else gives us more distinct blocks of logic and is generally way easier to follow, and gets rid of the indentation of the final logic. I'm always a fan of avoiding indenting deeper than required.
    if blah {
        doStuff()
        return
    }
    
    if blerp {
        otherStuff()
        return
    }
    
    finalStuff()
    

    Browser doesn't have a 'set tab length', and the indent was bothering me... <.< >.>

  • schussschuss Registered User regular
    Echo wrote: »
    On the subject of code reviews and coding style, I'm going to give some feedback to a junior dev about this stuff. I saw a bunch of code where it went
    if blah {
    	doStuff()
    	return
    } else if blerp {
    	otherStuff()
    	return
    } else {
    	finalStuff()
    }
    

    The else statements are redundant there, and of course it was more code than that, so it ended up really dense and hard to follow. Getting rid of the else gives us more distinct blocks of logic and is generally way easier to follow, and gets rid of the indentation of the final logic. I'm always a fan of avoiding indenting deeper than required.
    if blah {
    	doStuff()
    	return
    }
    
    if blerp {
    	otherStuff()
    	return
    }
    
    finalStuff()
    

    Note, not a dev (most of the time): the elifs aren't necessarily bad if you want to make it clear these are mutually exclusive conditions. If it wasn't commented, you could interpret this as "oh, when these conditions happen, fire off this function, regardless of other things".
    I've seen this mess with too many SQL and data things not to comment, as you need to make mutual exclusivity very clear when it happens.

  • zeenyzeeny Registered User regular
    I'm assuming the actual example is different than what he showed, because, well, it's really not improving the code(in specific context, it would be making it worse).
    The initial il/elif flows towards a single exit point for the fn. The "refactored" version doesn't. I would personally rarely use multiple exit points outside of handling errors/unexpected flow.

  • EchoEcho ski-bap ba-dapModerator mod
    Yeah, the actual code returns on handling errors, because Go.

  • thatassemblyguythatassemblyguy Janitor of Technical Debt .Registered User regular
    As Echo points out, the "if(error) { return } ... if (error) {return}" pattern is extremely common in embedded space.

    Ever since Dijkstra went HAM on GOTO statements, and because C doesn't have an exception-like option, the "if (error) { return }" pattern is pretty much the best way of keeping a function from being a series of 8-deep nested if's.

    Without GOTOs, however, you lose some efficiency and code space because the only other way to do a "catch" (instead of just a blind return, one might want to clean-up) is to inline a function, or call a function for the clean-up.

  • DehumanizedDehumanized Registered User regular
    in an ideal world one would simply never duplicate the return statement

    alas

  • EchoEcho ski-bap ba-dapModerator mod
    Wee, releasing brand new stuff we've never really done before! We're definitely finding out which parts of our infra is creaking at the seams. Need to take a pass and optimize a bunch of API calls.

    On that note, anyone have a hot take on websockets vs grpc?

  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    @vamen I want to be sure I am understanding your issue clearly. You have a listbox with a bunch of items in it, right? And you want to select multiple items based on a value from the database?

    If so, something like this might be what you need. Keep in mind that I ran this through a C# => VB.NET translator...
    Dim selectedItems As String() = {"itemCode1", "itemCode4", "ItemCode12"} // This is the selected items list that you are pulling from your database.
    
    For Each item As ListItem In Listbox1.Items
    
        If selectedItems.Contains(item.Value) Then
            item.Selected = True
        End If
    Next
    

  • vamenvamen Registered User regular
    edited August 2019
    hig39n8d74z5.jpg
    My hero!

    Man, I was SO close, but somehow I never ran across "contains" and that was what I really needed.
    You're correct in understanding what I needed (and probably badly explained). I used your code and it selected EVERYTHING, which is the opposite of selecting nothing...so I met in the middle and got it FINALLY working (thaaaaank you) with this:
    Dim selectedItems As String() = Split(survinfo.Rows(0)("condition"), ",")
    For Each item As ListItem In ddCondition.Items
      If selectedItems.Contains(item.Value) Then
        item.Selected = True
      End If
    Next
    

    I have no idea how ideal all my code (or how I set up my data tables) is for all of this... probably all sorts of a disaster, but man am I glad to finally get this last piece working.
    Very humbling to look at how little code it took to accomplish my goal compared to how LONG it took me to get it working =p.

    vamen on
  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    edited August 2019
    vamen wrote: »
    hig39n8d74z5.jpg
    My hero!

    Man, I was SO close, but somehow I never ran across "contains" and that was what I really needed.
    You're correct in understanding what I needed (and probably badly explained). I used your code and it selected EVERYTHING, which is the opposite of selecting nothing...so I met in the middle and got it FINALLY working (thaaaaank you) with this:
    Dim selectedItems As String() = Split(survinfo.Rows(0)("condition"), ",")
    For Each item As ListItem In ddCondition.Items
      If selectedItems.Contains(item.Value) Then
        item.Selected = True
      End If
    Next
    

    I have no idea how ideal all my code (or how I set up my data tables) is for all of this... probably all sorts of a disaster, but man am I glad to finally get this last piece working.
    Very humbling to look at how little code it took to accomplish my goal compared to how LONG it took me to get it working =p.

    Sometimes the best things are stupidly simple. That's precisely why saying "I wrote x lines of code more than you did!" is a terrible metric when evaluating the skill level of a developer.

    For example, several years ago I was working on an Angular project and having trouble getting different components to talk to each other. I had been using Angular events to bubble up to the parent component and pass the updates down to the other children, but it was clunky and made the components too tightly coupled together. So one night I decided to write something similar to a message bus. Different components could listen to a central queue for messages directed to them and process the attached data. So if I wanted to send a message from a component to update a shopping cart, it was a piece of cake.

    The best thing about it? It was 17 lines of code.

    Ear3nd1l on
  • vamenvamen Registered User regular
    I can't even start to imagine how all that works...I definitely wouldn't have guessed 17 lines of code would do it.

    My code started out as around 30 or 40 lines so I'm glad I got it down to such a small amount =p.

  • electricitylikesmeelectricitylikesme Registered User regular
    Echo wrote: »
    Wee, releasing brand new stuff we've never really done before! We're definitely finding out which parts of our infra is creaking at the seams. Need to take a pass and optimize a bunch of API calls.

    On that note, anyone have a hot take on websockets vs grpc?

    Machines are going to fail, then the system is going to fail, then it's about who has the will to survive...

  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    Echo wrote: »
    Wee, releasing brand new stuff we've never really done before! We're definitely finding out which parts of our infra is creaking at the seams. Need to take a pass and optimize a bunch of API calls.

    On that note, anyone have a hot take on websockets vs grpc?

    Do you love protocol buffers?
    Do you need complex RPC semantics? (Parallel requests, many messages per request)
    If the answer to both is yes then grpc is fine

  • zeenyzeeny Registered User regular
    Naah, those two things don't have a comparable use case.

    The use case for websockets is very limited, only in terms of very concrete need of sessions and push semantics. Using websockets (usually) has absolutely no implication on ops and one just needs to be careful with the long term connection per session tradeoff.

    GRPC is just a regular RPC framework on top of protobuffs. There are very clear tradeoffs and advantages in moving to a binary format vs cleartext serialization for team productivity. Make no mistake, GRPC requires a significant amount of additional tooling in dev and ops both(depending on how mature your team is, this could be from "almost none" to "lol, we can't do that"). I've phased GRPC in and I've also phased GRPC out of production. In general I've found that:
    - It's a lot easier to *start* with GRPC than migrate to GRPC.
    - If you want json/grpc to live side by side even with jsonproxy etc, it will be a pain.

    Personally, I'm not using GRPC in small teams and/or new domains again and I'd say that GRPC requires complete buy-in for successful rollout.

    PS: https://github.com/twitchtv/twirp carries some of the benefits of GRPC with reduced ops complexity.

  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    Have I mentioned how much I hate TFS??? I created a new branch to work on the next app feature. I modified one file and there were a bunch of changes in this new branch that I didn't make. So I decided that I would check them in and start a new branch from the Trunk branch. But instead of checking them into the new branch (which I had open), it checked it into the Trunk branch.

    giphy.gif

  • gavindelgavindel The reason all your software is brokenRegistered User regular
    Microsoft bought Git. If that's not a rousing endorsement of TFS, I don't know what is. :bzz:

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • OrcaOrca Also known as Espressosaurus WrexRegistered User regular
    Even Microsoft is moving away from TFS, so you’re actually correct.

  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    I wish my client would...

  • schussschuss Registered User regular
    Orca wrote: »
    Even Microsoft is moving away from TFS, so you’re actually correct.

    They're actually the largest corporate user of GitHub.

  • tastydonutstastydonuts Registered User regular
    Are any of you guys really familiar with Crystal Syntax?

    “I used to draw, hard to admit that I used to draw...”
  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    Sorry, I might have been able to help you 20 years ago...

  • FireflashFireflash Montreal, QCRegistered User regular
    edited August 2019
    I've been searching google for a while and maybe I'm just not expressing properly what I need because I'm running in circles and pulling my hair.

    This is for Python.

    I'm trying to create a time series but everything I find is showing me how to manipulate a time series and create nice tables and graphs using the pandas module. Plenty of info for that I can figure it out once I reach that point.

    But I don't have the time series that contains ranges of time with a count for each range. what I have is the raw data that looks something like this:

    [('timestamp', 'data1', 'data2', '...', 'status_code'),]

    and I want to make this a time series where I can have the count and 'good requests/ total requests' based on the return code of each entry, in a given timeframe and interval.

    Every tutorial I see already starts with data that is already a timestamp + some kind of count in the interval.


    Please anyone point me in the right direction to start. I feel dumb. :(

    EDIT: OK I figured it out I think...

    I just had to create a function that would evaluate the status_code and return 1 if it's a good code. Then I just created a column using this function after which I can df.resample().sum() to have it how I want.

    Fireflash on
    PSN: PatParadize
    Battle.net: Fireflash#1425
    Steam Friend code: 45386507
  • EchoEcho ski-bap ba-dapModerator mod
    msgCount >= 1
    

    2cmlb2x0afd6.png

  • bowenbowen How you doin'? Registered User regular
    edited August 2019
    so I've been troubleshooting this issue with this repo for fucking ever and it just came to a head not too long ago when I had to do some major updates and I couldn't see my diffs and it was bothering me

    but

    if you've got an older repository and work with C# and .NET like I do, at some point git/github added csharp as a special diff option, and it broke diffs. So if you don't see any diff in your git client, give a quick look at your gitattributes file and change
    *.cs     diff=astextplain
    
    to
    *.cs     diff=csharp
    

    And suddenly your diffs/history will start working again

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • OrcaOrca Also known as Espressosaurus WrexRegistered User regular
    Lol git

  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    bowen wrote: »
    so I've been troubleshooting this issue with this repo for fucking ever and it just came to a head not too long ago when I had to do some major updates and I couldn't see my diffs and it was bothering me

    but

    if you've got an older repository and work with C# and .NET like I do, at some point git/github added csharp as a special diff option, and it broke diffs. So if you don't see any diff in your git client, give a quick look at your gitattributes file and change
    *.cs     diff=astextplain
    
    to
    *.cs     diff=csharp
    

    And suddenly your diffs/history will start working again

    That's a weird one.
    Orca wrote: »
    Lol git

    Well, it's no TFS...

  • OrcaOrca Also known as Espressosaurus WrexRegistered User regular
    You only use TFS if you hate yourself.

  • mightyjongyomightyjongyo Sour Crrm East Bay, CaliforniaRegistered User regular
    *cries in Synergy*

  • Ear3nd1lEar3nd1l Eärendil the Mariner, father of Elrond Registered User regular
    Orca wrote: »
    You only use TFS if you hate yourself.

    Or your client hates you. The core API of the project I'm working on is so antiquated it's not funny. I'm pretty sure it's what the British used to manage their logistics during the War of 1812.

  • EchoEcho ski-bap ba-dapModerator mod
    Goddamn Heisenbugs.

    I think I isolated a bug to a third-party package that has an error-handling function that can in theory receive a nil error, causing a panic. I added some debug logging to verify this, and now the damn thing just refuses to happen.

This discussion has been closed.