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/
Options

My Little [Programming] Thread: Debugging is Magic

11920222425100

Posts

  • Options
    Jimmy KingJimmy King Registered User regular
    urahonky wrote: »
    What's the most common practice for naming folders in Linux with spaces in them?

    sec_lib or sec-lib?
    You can also just use a space, although it's irritating because then you have to remember to put quotes around the full name for most uses. Keep that in mind though, because sometimes it happens.

    I usually go with sec_lib. The underscore gets out of the way so I can see the separate letters/words more clearly than with sec-lib.

  • Options
    EndEnd Registered User regular
    I didn't actually use it, but today I wrote this because I was curious.

    [...]

    This way, you can write functions that will do a thing to every instance of this class in a list, and that same function will do that same thing to just one instance if you only give it one instance.

    I can't decide if this is pythonic because duck typing or unpythonic because it's disgusting.

    Why not do this?
    def __iter__(self):
        yield self
    

    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpg
  • Options
    undergroundmonorailundergroundmonorail single-track subway Registered User regular
    End wrote: »
    I didn't actually use it, but today I wrote this because I was curious.

    [...]

    This way, you can write functions that will do a thing to every instance of this class in a list, and that same function will do that same thing to just one instance if you only give it one instance.

    I can't decide if this is pythonic because duck typing or unpythonic because it's disgusting.

    Why not do this?
    def __iter__(self):
        yield self
    
    Fuck

    Pokémon X | 3DS Friend Code: 0490-4897-7688
    Friend Safari: Fighting - Machoke, Pancham, Riolu | In game name: Jessica
    Official Weather Gym Leader of the G+T Pokémon League. @me to try for the Climate Badge!
  • Options
    LD50LD50 Registered User regular
    In ruby you can do:
    class Thing
    
      def method_missing(*args)
        yield self if block_given?
      end
    
    end
    

    Which will do the same thing but is even dirtier.

  • Options
    undergroundmonorailundergroundmonorail single-track subway Registered User regular
    edited April 2014
    @Infidel You wanted to be kept in the loop

    I haven't submitted the challenge, since there's a similar challenge going on right now that hasn't gotten enough attention so I don't want to butt in and steal any thunder. I have the code for the engine here, if you're interested.
    please don't judge me i know i'm not a good programmer

    I did end up deciding that whispers were going to be too much work.

    undergroundmonorail on
    Pokémon X | 3DS Friend Code: 0490-4897-7688
    Friend Safari: Fighting - Machoke, Pancham, Riolu | In game name: Jessica
    Official Weather Gym Leader of the G+T Pokémon League. @me to try for the Climate Badge!
  • Options
    Jimmy KingJimmy King Registered User regular
    @undergroundmonorail‌ That self returning iterator is badass. Pretty sure I won't actually use it in my code because it's sneaky and unexpected, but I still have to admit that it's awesome. Needing an actual iterable passed in and no way to enforce it or even make it clear other than hoping the next developer reads docstrings is something that frequently annoys me. It is somewhat tempting to at least slap this on the in-house classes that are expected to be passed in as lists to functions as it comes up to somewhat mitigate that risk.

  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    set up a jekyll website yesterday

    jekyll is the best website thing, boot strap a close second

  • Options
    EchoEcho ski-bap ba-dapModerator mod
    Jasconius wrote: »
    set up a jekyll website yesterday

    jekyll is the best website thing, boot strap a close second

    I run my blahg on Octopress, which is pretty much just a theme engine on top of Jekyll.

  • Options
    PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    @Infidel You wanted to be kept in the loop

    I haven't submitted the challenge, since there's a similar challenge going on right now that hasn't gotten enough attention so I don't want to butt in and steal any thunder. I have the code for the engine here, if you're interested.
    please don't judge me i know i'm not a good programmer

    I did end up deciding that whispers were going to be too much work.

    I don't see where you tell players what their name is

  • Options
    LD50LD50 Registered User regular
    Jimmy King wrote: »
    @undergroundmonorail‌ That self returning iterator is badass. Pretty sure I won't actually use it in my code because it's sneaky and unexpected, but I still have to admit that it's awesome. Needing an actual iterable passed in and no way to enforce it or even make it clear other than hoping the next developer reads docstrings is something that frequently annoys me. It is somewhat tempting to at least slap this on the in-house classes that are expected to be passed in as lists to functions as it comes up to somewhat mitigate that risk.

    Thinking a little more about this: This might be the Ruby in me talking, but I don't think the self returning iterator is a bad idea, as long as it's clear that it's happening.

    Just because there will only ever be one element returned doesn't mean that the object isn't iterable. It still has well defined iteration.

    The alternatives I can think of aren't really any better. You could either wrap the object in an iterable thing like an array (Which seems kludgy to me), or you can wrap your code in some conditional checks to make sure you're not trying to iterate over something that's not iterable (which just adds complexity to something that's otherwise pretty clear).

  • Options
    DehumanizedDehumanized Registered User regular
    If you're looking at trying out a VPS service, DigitalOcean is running a nice promo. I've had good experiences with their service.

  • Options
    Jimmy KingJimmy King Registered User regular
    LD50 wrote: »
    Jimmy King wrote: »
    @undergroundmonorail‌ That self returning iterator is badass. Pretty sure I won't actually use it in my code because it's sneaky and unexpected, but I still have to admit that it's awesome. Needing an actual iterable passed in and no way to enforce it or even make it clear other than hoping the next developer reads docstrings is something that frequently annoys me. It is somewhat tempting to at least slap this on the in-house classes that are expected to be passed in as lists to functions as it comes up to somewhat mitigate that risk.

    Thinking a little more about this: This might be the Ruby in me talking, but I don't think the self returning iterator is a bad idea, as long as it's clear that it's happening.

    Just because there will only ever be one element returned doesn't mean that the object isn't iterable. It still has well defined iteration.

    The alternatives I can think of aren't really any better. You could either wrap the object in an iterable thing like an array (Which seems kludgy to me), or you can wrap your code in some conditional checks to make sure you're not trying to iterate over something that's not iterable (which just adds complexity to something that's otherwise pretty clear).

    Oh yeah, overall I like it. It's not what people are generally going to expect the behavior to be of a single object in most cases (unless that object is a string), and for me, doesn't really fix the problem I'd like to use it to solve (because you need type checking or interface checking to fix it correctly). I can go and add that to all of our own classes in our codebases and then if someone accidentally passes a single instance of one of those objects into something expecting an iterable of them we're fine. But they still could pass any number of other objects are not iterable. So it provides some unexpected behavior (an iterable single object) while only fixing the main use case I have for it in very specific cases. I think it would end up just covering up mistakes so that they are harder to find and appear somewhere else less clear later in the code in the code bases I work with.

    It's a cool idea for sure and there are probably some great use cases for it, just not for me personally in my usual coding.

  • Options
    undergroundmonorailundergroundmonorail single-track subway Registered User regular
    Phyphor wrote: »
    @Infidel You wanted to be kept in the loop

    I haven't submitted the challenge, since there's a similar challenge going on right now that hasn't gotten enough attention so I don't want to butt in and steal any thunder. I have the code for the engine here, if you're interested.
    please don't judge me i know i'm not a good programmer

    I did end up deciding that whispers were going to be too much work.

    I don't see where you tell players what their name is
    They'll tell me what their name is and I'll make a folder with that name.

    Pokémon X | 3DS Friend Code: 0490-4897-7688
    Friend Safari: Fighting - Machoke, Pancham, Riolu | In game name: Jessica
    Official Weather Gym Leader of the G+T Pokémon League. @me to try for the Climate Badge!
  • Options
    LD50LD50 Registered User regular
    Jimmy King wrote: »
    LD50 wrote: »
    Jimmy King wrote: »
    @undergroundmonorail‌ That self returning iterator is badass. Pretty sure I won't actually use it in my code because it's sneaky and unexpected, but I still have to admit that it's awesome. Needing an actual iterable passed in and no way to enforce it or even make it clear other than hoping the next developer reads docstrings is something that frequently annoys me. It is somewhat tempting to at least slap this on the in-house classes that are expected to be passed in as lists to functions as it comes up to somewhat mitigate that risk.

    Thinking a little more about this: This might be the Ruby in me talking, but I don't think the self returning iterator is a bad idea, as long as it's clear that it's happening.

    Just because there will only ever be one element returned doesn't mean that the object isn't iterable. It still has well defined iteration.

    The alternatives I can think of aren't really any better. You could either wrap the object in an iterable thing like an array (Which seems kludgy to me), or you can wrap your code in some conditional checks to make sure you're not trying to iterate over something that's not iterable (which just adds complexity to something that's otherwise pretty clear).

    Oh yeah, overall I like it. It's not what people are generally going to expect the behavior to be of a single object in most cases (unless that object is a string), and for me, doesn't really fix the problem I'd like to use it to solve (because you need type checking or interface checking to fix it correctly). I can go and add that to all of our own classes in our codebases and then if someone accidentally passes a single instance of one of those objects into something expecting an iterable of them we're fine. But they still could pass any number of other objects are not iterable. So it provides some unexpected behavior (an iterable single object) while only fixing the main use case I have for it in very specific cases. I think it would end up just covering up mistakes so that they are harder to find and appear somewhere else less clear later in the code in the code bases I work with.

    It's a cool idea for sure and there are probably some great use cases for it, just not for me personally in my usual coding.

    Yeah, I agree with you there. I wouldn't add it to a whole code base, and I wouldn't use the strategy all over a project. I could see it being straightforward if you kept those iterators confined to specific methods that were flagged as only taking iterators, and only adding the self-iterator code to classes you were intending on mixing into the collection streams that those methods are getting.

  • Options
    durandal4532durandal4532 Registered User regular
    So in an effort to become more employable and also sell off my comics in a manner that no longer depends on a distressingly gigantic Excel spreadsheet I'm trying to bone up on my slightly lapsed SQL skills.

    Here's the thing I'm realizing: everything I've previously done has specifically been in Microsoft Access, which I recall hating with a passion. If you were starting a database from scratch, what would you use to do so? Currently I'm trying to figure out the MySQL Cluster public release.

    Take a moment to donate what you can to Critical Resistance and Black Lives Matter.
  • Options
    Jimmy KingJimmy King Registered User regular
    MySQL Cluster seems it is probably serious overkill with lots of excess configuration and admin headaches to worry about unless their naming scheme has gotten weird.

    Since it sounds like you're intending to have this living on Windows it is probably worth having a look at SQL Server Express. It'll just install, it integrates nicely with Windows stuff, etc. and is likely your best option unless you've got some reason for specifically wanting something else. If you want to use on of the more unix/linux oriented open source DBs then plain old MySQL or Postgresql will work. My preference of the two is Postgresql, but either is fine. For just starting off and fiddling around you could even use SQLite, which is far lighter weight, no admin overhead, etc.

  • Options
    ecco the dolphinecco the dolphin Registered User regular
    Goddamn it Boost!

    You're solving all my problems too quickly! =P

    First, I wanted a cross platform network library... and you give me boost::asio, which is quite nice.

    Next, I was all, "Lock free queue me!"

    And lo, there is boost::lockfree

    *mutter*mutter*how do they do this*mutter*mutter*

    *mutter*mutter*goddamn it so productive now I can actually get on to actual project related coding instead of overhead fluffery*mutter*mutter*

    I sorta did want to do my own lock free queue, but at the same time... man, it's quite non-trivial.

    You win this round, boost!

    Penny Arcade Developers at PADev.net.
  • Options
    gavindelgavindel The reason all your software is brokenRegistered User regular
    Engineering textbooks are the worst.
    Except for engineering textbooks written by your professor.

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    about two weeks from an alpha. didn't get much done this weekend, but I did do some modding to the physics engine so that the characters physical bounds were not determined by their visual bounds

    I want to do a devblog but I don't what to write to actually kick it off.

  • Options
    Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    Ok, so I am starting my own little coding project that requires DB integration. It will almost certainly end up having a web front end.

    But I am trying to set up the database, and was wondering whether there's a way to do the following:

    Table, group has two columns, name and id (group.id being the primary key)
    Table, item has three columns id, name, groupid (with item.id being the primary key and groupid being the foreign key)

    Is there any way to constrain the values for groupid to group.id's records but show the group.name entry? Or is that something that is entirely the domain of the application? And if so, is there a particular name or technique that it is called? It's fairly obvious how one could do it, but I don't want to reinvent the wheel/do something less well than those before me.

    If there's a tutorial or guide that I should look for? I think, ideally I'd like to use MySQL and Python so Django or similar things would be ideal.

    Fake edit: reading this it seems like a particularly clueless and obvious question. Still, anything you could steer me toward will be appreciated.

  • Options
    El SkidEl Skid The frozen white northRegistered User regular
    I can take a stab at this.

    Having a foreign key means that you're restricting the possible values of item.groupid to values contained in the group table, so you're good there.

    What your application is showing is totally up to the application. As far as the database is concerned the data is all there to see, but your application will probably be calling something like this:

    Select item.name, group.name
    from item, group
    where item.id = <value> and item.groupid = group.id

    ...which would return the item name and group name for a specific item.

    I think that's what you wanted to know (maybe? :P)

  • Options
    templewulftemplewulf The Team Chump USARegistered User regular
    edited April 2014
    Apothe0sis wrote: »
    Ok, so I am starting my own little coding project that requires DB integration. It will almost certainly end up having a web front end.

    But I am trying to set up the database, and was wondering whether there's a way to do the following:

    Table, group has two columns, name and id (group.id being the primary key)
    Table, item has three columns id, name, groupid (with item.id being the primary key and groupid being the foreign key)

    Is there any way to constrain the values for groupid to group.id's records but show the group.name entry? Or is that something that is entirely the domain of the application? And if so, is there a particular name or technique that it is called? It's fairly obvious how one could do it, but I don't want to reinvent the wheel/do something less well than those before me.

    If there's a tutorial or guide that I should look for? I think, ideally I'd like to use MySQL and Python so Django or similar things would be ideal.

    Fake edit: reading this it seems like a particularly clueless and obvious question. Still, anything you could steer me toward will be appreciated.

    I'm not entirely sure I understand your requirements, but my impression is that you want to show only records from item whose groupid matches a record with group.id. You'd typically do that with a join, like so:
    SELECT g.id, g.name, i.id, i.name
    FROM item AS i
    INNER JOIN group AS g
    ON i.groupid = g.id
    

    Check out resources on Foreign Keys and Joins.

    Edit:
    One thing that helped me understand the different kinds of joins (like why I used an inner join up there) is the venn diagrams you sometimes see: http://www.codeproject.com/KB/database/Visual_SQL_Joins/Visual_SQL_JOINS_orig.jpg

    Edit2:
    I've realized my confusion lies around the possible meanings of "constrain". Do you mean you want to filter query results in such a way or to out and out prevent insertions, such that the DB will never be in a particular state?

    templewulf on
    Twitch.tv/FiercePunchStudios | PSN | Steam | Discord | SFV CFN: templewulf
  • Options
    a5ehrena5ehren AtlantaRegistered User regular
    edited April 2014
    Apparently the Perl build scripts will only go two directories deep to add extensions during the build (we cross-compile, so the "normal" way isn't an option). Yay for editing Makefile.pl I guess?

    a5ehren on
  • Options
    GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    Goddamn it Boost!

    You're solving all my problems too quickly! =P

    First, I wanted a cross platform network library... and you give me boost::asio, which is quite nice.

    Next, I was all, "Lock free queue me!"

    And lo, there is boost::lockfree

    *mutter*mutter*how do they do this*mutter*mutter*

    *mutter*mutter*goddamn it so productive now I can actually get on to actual project related coding instead of overhead fluffery*mutter*mutter*

    I sorta did want to do my own lock free queue, but at the same time... man, it's quite non-trivial.

    You win this round, boost!

    Careful with ASIO. I had it blow up in my face on Windows once where we expected it to use IOCP's and scale, and it did not. This could have been corrected, but at one time it only had an epoll implementation and all other implementations were done using threads/select. I know it has kqueue now, but no idea about IOCP's on Windows.

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • Options
    BarrakkethBarrakketh Registered User regular
    GnomeTank wrote: »
    Careful with ASIO. I had it blow up in my face on Windows once where we expected it to use IOCP's and scale, and it did not. This could have been corrected, but at one time it only had an epoll implementation and all other implementations were done using threads/select. I know it has kqueue now, but no idea about IOCP's on Windows.
    I presume it has an IOCP backend now since a quick glance at the documentation revealed a BOOST_ASIO_DISABLE_IOCP define if you'd rather disable support for it.

    Rollers are red, chargers are blue....omae wa mou shindeiru
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    Barrakketh wrote: »
    GnomeTank wrote: »
    Careful with ASIO. I had it blow up in my face on Windows once where we expected it to use IOCP's and scale, and it did not. This could have been corrected, but at one time it only had an epoll implementation and all other implementations were done using threads/select. I know it has kqueue now, but no idea about IOCP's on Windows.
    I presume it has an IOCP backend now since a quick glance at the documentation revealed a BOOST_ASIO_DISABLE_IOCP define if you'd rather disable support for it.

    Thanks for the heads up, guys. =)

    My server is only expected to handle max ~10 connections (typ. 1-4 connections) with maybe a ~1kbytes/socket/s max, so I suppose I'd be okay either way. =)

    Penny Arcade Developers at PADev.net.
  • Options
    GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    Barrakketh wrote: »
    GnomeTank wrote: »
    Careful with ASIO. I had it blow up in my face on Windows once where we expected it to use IOCP's and scale, and it did not. This could have been corrected, but at one time it only had an epoll implementation and all other implementations were done using threads/select. I know it has kqueue now, but no idea about IOCP's on Windows.
    I presume it has an IOCP backend now since a quick glance at the documentation revealed a BOOST_ASIO_DISABLE_IOCP define if you'd rather disable support for it.

    Good call. I haven't looked in to the deep innards of boost.asio in a while, so I have no doubt it has full IOCP support now.

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • Options
    undergroundmonorailundergroundmonorail single-track subway Registered User regular
    Commit messages are the most pure window into my deepest thoughts.
    myjMCoD.png

    Pokémon X | 3DS Friend Code: 0490-4897-7688
    Friend Safari: Fighting - Machoke, Pancham, Riolu | In game name: Jessica
    Official Weather Gym Leader of the G+T Pokémon League. @me to try for the Climate Badge!
  • Options
    ASimPersonASimPerson Cold... and hard.Registered User regular
    edited April 2014
    git_commit.png

    ASimPerson on
  • Options
    undergroundmonorailundergroundmonorail single-track subway Registered User regular
    Eh, not quite.
    rJYtvWz.png
    (very scientific graph)

    Pokémon X | 3DS Friend Code: 0490-4897-7688
    Friend Safari: Fighting - Machoke, Pancham, Riolu | In game name: Jessica
    Official Weather Gym Leader of the G+T Pokémon League. @me to try for the Climate Badge!
  • Options
    gavindelgavindel The reason all your software is brokenRegistered User regular
    At my group meeting, nobody cared about the extensive back end work. They did, however, squee over the fact my table of information had clickable titles that linked into the data base for each one, so you could click a title and be taken to its details and comments.

    This project may be trite, but the "front end guy' feeling is authentic.

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • Options
    JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited April 2014
    screenshot of my alpha

    everything is google image search, except the rabbit, which is original by my artist. im hoping he gets more time to start churning things out

    all the GUI there is hooked up too. the only part of the GUI that's buggy right now is the chat window as its literally the first GUI piece I wrote while I was still learning the font libs

    i didn't really think about the fact that I was hanging off the map when I took it.
    screen002.png

    Jasconius on
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    Jasconius wrote: »
    screenshot of my alpha

    everything is google image search, except the rabbit, which is original by my artist. im hoping he gets more time to start churning things out

    all the GUI there is hooked up too. the only part of the GUI that's buggy right now is the chat window as its literally the first GUI piece I wrote while I was still learning the font libs

    i didn't really think about the fact that I was hanging off the map when I took it.

    UR-RABBIT ANGRY! UR-RABBIT CHEW!

    Penny Arcade Developers at PADev.net.
  • Options
    AnteCantelopeAnteCantelope Registered User regular
    I've been doing a lot of reading and research on a bunch of topics to try to improve my programming skills, but my memory is... maybe a little faulty. So I'm looking at making some sort of knowledge base to keep track of this stuff. It's just for myself, though if other people can access it that's OK.

    Does anyone have any recommendations on some sort of knowledge base system? I'm thinking something like a Wordpress blog, because I want to be able to add tags like "Java", "Design Patterns" to one post and "Python", "Web Scraping" to another and then search for "Web Scraping" and get everything I've written about web scraping in any language. A wiki doesn't seem like a good fit for that sort of system. Pen and Paper is a pretty poor choice for searching, OneNote seems like it needs more rigidly defined categories with everything in one category (it was great in uni, fit well to lectures and such), and I can't think of any other good options. Is there something else that would be better suited to this than Wordpress?

  • Options
    Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    You could try something like PersonalBrain/TheBrain, maybe?

  • Options
    Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    templewulf wrote: »
    Apothe0sis wrote: »
    Ok, so I am starting my own little coding project that requires DB integration. It will almost certainly end up having a web front end.

    But I am trying to set up the database, and was wondering whether there's a way to do the following:

    Table, group has two columns, name and id (group.id being the primary key)
    Table, item has three columns id, name, groupid (with item.id being the primary key and groupid being the foreign key)

    Is there any way to constrain the values for groupid to group.id's records but show the group.name entry? Or is that something that is entirely the domain of the application? And if so, is there a particular name or technique that it is called? It's fairly obvious how one could do it, but I don't want to reinvent the wheel/do something less well than those before me.

    If there's a tutorial or guide that I should look for? I think, ideally I'd like to use MySQL and Python so Django or similar things would be ideal.

    Fake edit: reading this it seems like a particularly clueless and obvious question. Still, anything you could steer me toward will be appreciated.

    I'm not entirely sure I understand your requirements, but my impression is that you want to show only records from item whose groupid matches a record with group.id. You'd typically do that with a join, like so:
    SELECT g.id, g.name, i.id, i.name
    FROM item AS i
    INNER JOIN group AS g
    ON i.groupid = g.id
    

    Check out resources on Foreign Keys and Joins.

    Edit:
    One thing that helped me understand the different kinds of joins (like why I used an inner join up there) is the venn diagrams you sometimes see: http://www.codeproject.com/KB/database/Visual_SQL_Joins/Visual_SQL_JOINS_orig.jpg

    Edit2:
    I've realized my confusion lies around the possible meanings of "constrain". Do you mean you want to filter query results in such a way or to out and out prevent insertions, such that the DB will never be in a particular state?
    El Skid's more or less answered my question/confirmed things for me. Many thanks though. :)

  • Options
    Jimmy KingJimmy King Registered User regular
    @AnteCantelope‌ It seems like any blogging system with tagging would do what you want. If this is all about learning then the obvious answer is to build your own that does exactly what you want.

  • Options
    El SkidEl Skid The frozen white northRegistered User regular
    Apothe0sis wrote: »
    templewulf wrote: »
    Apothe0sis wrote: »
    Ok, so I am starting my own little coding project that requires DB integration. It will almost certainly end up having a web front end.

    But I am trying to set up the database, and was wondering whether there's a way to do the following:

    Table, group has two columns, name and id (group.id being the primary key)
    Table, item has three columns id, name, groupid (with item.id being the primary key and groupid being the foreign key)

    Is there any way to constrain the values for groupid to group.id's records but show the group.name entry? Or is that something that is entirely the domain of the application? And if so, is there a particular name or technique that it is called? It's fairly obvious how one could do it, but I don't want to reinvent the wheel/do something less well than those before me.

    If there's a tutorial or guide that I should look for? I think, ideally I'd like to use MySQL and Python so Django or similar things would be ideal.

    Fake edit: reading this it seems like a particularly clueless and obvious question. Still, anything you could steer me toward will be appreciated.

    I'm not entirely sure I understand your requirements, but my impression is that you want to show only records from item whose groupid matches a record with group.id. You'd typically do that with a join, like so:
    SELECT g.id, g.name, i.id, i.name
    FROM item AS i
    INNER JOIN group AS g
    ON i.groupid = g.id
    

    Check out resources on Foreign Keys and Joins.

    Edit:
    One thing that helped me understand the different kinds of joins (like why I used an inner join up there) is the venn diagrams you sometimes see: http://www.codeproject.com/KB/database/Visual_SQL_Joins/Visual_SQL_JOINS_orig.jpg

    Edit2:
    I've realized my confusion lies around the possible meanings of "constrain". Do you mean you want to filter query results in such a way or to out and out prevent insertions, such that the DB will never be in a particular state?
    El Skid's more or less answered my question/confirmed things for me. Many thanks though. :)

    One further bit of best practice if your database is going to get any more complicated than what you have now:

    Be careful about deleting stuff from your core tables, ie using the DELETE command. It's fine if you're deleting from a less important table (like a table that just has a relationship between entities) of course.

    In my experience, it's really much better to add a column like "ACTIVE" which is either a "1" or a "0", and maybe a last modified date column. So if your application wants to delete something, it just sets the ACTIVE flag to 0, and you can just make sure your regular queries to the database are just checking the ones with ACTIVE = 1.

    This will do a few things:

    - If you have a bug where stuff gets accidentally deleted it'll be much easier to recover, and also debug. (this happens)
    - Undeleting things becomes so much easier
    - It opens up a whole bunch of metrics data for you to go over as your program is used- you can see when stuff was deleted, what it was etc.
    - You don't have to worry about cascading deletions across multiple tables, which can get messy and introduce bugs.

    Hope that's helpful!

  • Options
    IncindiumIncindium Registered User regular
    I've been doing a lot of reading and research on a bunch of topics to try to improve my programming skills, but my memory is... maybe a little faulty. So I'm looking at making some sort of knowledge base to keep track of this stuff. It's just for myself, though if other people can access it that's OK.

    Does anyone have any recommendations on some sort of knowledge base system? I'm thinking something like a Wordpress blog, because I want to be able to add tags like "Java", "Design Patterns" to one post and "Python", "Web Scraping" to another and then search for "Web Scraping" and get everything I've written about web scraping in any language. A wiki doesn't seem like a good fit for that sort of system. Pen and Paper is a pretty poor choice for searching, OneNote seems like it needs more rigidly defined categories with everything in one category (it was great in uni, fit well to lectures and such), and I can't think of any other good options. Is there something else that would be better suited to this than Wordpress?

    Scrivener maybe?

    http://www.literatureandlatte.com/scrivener.php

    I've been wanting for an excuse to buy that myself cause it looks so cool but I don't do any writing or really have a practical use for it.

    steam_sig.png
    Nintendo ID: Incindium
    PSN: IncindiumX
  • Options
    GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    Finally got the UE4 engine to build last night. Apparently if your VS12COMMONTOOLS environment variable is pointing to some random place in space, and not your actual VS2013 install, weird things happen.

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
This discussion has been closed.