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/
We're funding a new Acquisitions Incorporated series on Kickstarter right now! Check it out at https://www.kickstarter.com/projects/pennyarcade/acquisitions-incorporated-the-series-2

using(PennyArcade.Forum){Threads.push(ProgrammingThread())}

1444547495063

Posts

  • EndEnd Registered User regular
    edited April 2010
    By the way, if anyone wants to see an abuse of switch statements (if I've ever seen one), look up Duff's Device. :P

    End on
    I wish that someway, somehow, that I could save every one of us
    zaleiria-by-lexxy-sig.jpgsteam~tinythumb.png
  • CangoFettCangoFett Registered User regular
    edited April 2010
    K, thanks for all your help guys. Any online resources that anyone would specifically reccomend so I dont keep spamming up this thread?

    CangoFett on
  • ASimPersonASimPerson Cold... and hard.Registered User regular
    edited April 2010
    http://www.cppreference.com/wiki/ is a good site for C and C++ references

    Also, asking questions in this thread is fine. That's why it's here.

    ASimPerson on
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited April 2010
    I was gonna say...isn't this thread sort of here just for this purpose? To discuss and educate about programming? I wouldn't worry to much about "spamming" the thread with questions. Most of us probably like answering them (I know I do).

    GnomeTank on
    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
  • urahonkyurahonky Registered User regular
    edited April 2010
    So I'm trying to do something for my personal area networks class. I am currently running Ubuntu Live trying to get iwlist to work. After two hours of fumbling around I finally got this dang thing on the wireless network.

    Now I need to make a script or something that runs iwlist and somehow takes the data out of the information provided and puts it into a file. Specifically the signal strength. AND I need this to run every 30 seconds for 30 minutes.

    How the living hell am I going to do this? I have extremely limited shell script experience. In fact the only experience I have for it is just creating something that runs my program without me having to type it into the terminal window.

    I just googled it and it looks like it's way over my head, but everyone in my class seems to have had no problems with it so far. So where do I look? I don't even know how to make a timer or anything like that. :( I'm nervous now.

    urahonky on
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited April 2010
    Write your script in something easy to use (Ruby or Python come to mind), then setup an .sh script that is cronned. Have that SH script run iwlist then pipe it as input to your Ruby program: iwlist | myscript.rb, for instance.

    e: Actually I think to pipe input, you need to use backticks ` `, but I can't remember. Look up piping input on Linux.

    GnomeTank on
    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
  • urahonkyurahonky Registered User regular
    edited April 2010
    But how do you the timing thing? That's the most confusing part to me. I see there is a time function but it doesn't do anything but tell you how long a command takes. I'm unable to think of a way to do something every 30 seconds for 30 minutes.

    urahonky on
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited April 2010
    Cron. Look up UNIX cron. Or does your timing solution have to be integrated in to the script?

    If that's the case, you'll want to use a Timer class inside your script. I am almost certain Ruby and Python have timer classes in their default libraries.

    Psuedo Code (if you can't use Cron):
    t = new Timer()
    t.interval = 30 seconds
    t.function = DoTick
    t.start
    
    startTime = CurrentTime()
    
    function DoTick()
        CallIWListAndParseInput()
        if CurrentTime() - startTime == 30 minutes then
          t.stop
        end
    end
    
    

    GnomeTank on
    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
  • BarrakkethBarrakketh Registered User regular
    edited April 2010
    iwlist? If you want the signal strength you can use iwconfig. Assuming you mean signal strength instead of link quality:
    iwconfig wlan0 | egrep -o 'Signal level=-[0-9]{1,3} dBm'
    

    If you just want the numeric value you can further strip it down:
    iwconfig wlan0 | egrep -o 'Signal level=-[0-9]{1,3} dBm' | egrep -o '\-[0-9]{1,3}
    

    EDIT: removed cron bit due to a derp on my part.

    Barrakketh on
    Rollers are red, chargers are blue....omae wa mou shindeiru
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited April 2010
    He specifically mentioned he must write a script to parse iwlists output, which is why I suggested my idea. Yes, using iwconfig is the easier way to get this information.

    GnomeTank on
    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
  • BarrakkethBarrakketh Registered User regular
    edited April 2010
    GnomeTank wrote: »
    He specifically mentioned he must write a script to parse iwlists output, which is why I suggested my idea. Yes, using iwconfig is the easier way to get this information.

    I was operating under the assumption that he wanted information about the currently connected network, not a list of the signal strength of all access points since that would require more information than just the signal strength in order for you to tell which value belongs to which AP.

    If any event, you could replace the iwconfig command in my example with "iwlist wlan0 scanning" and it will still work.

    Barrakketh on
    Rollers are red, chargers are blue....omae wa mou shindeiru
  • xzzyxzzy Registered User regular
    edited April 2010
    cron doesn't have resolution greater than one minute.

    If you need something done every 30 seconds, the best way is to use the 'sleep' command. ie:
    while true; do
       iwlist | grep whatever
       sleep 30
    done
    

    xzzy on
  • urahonkyurahonky Registered User regular
    edited April 2010
    Huh. I didn't know you could use while loops in a shell script. And yeah it seems crom doesn't run? I made a simple test script that only did an ls and put it into a .txt file but it never ran. It says online that it runs immediately after saving but I couldn't get it to work.

    However the while loop worked. I'll just have to set an alarm for 30 minutes immediately after starting it?

    urahonky on
  • khainkhain Registered User regular
    edited April 2010
    Change the script slightly to just run 60 times if you want 30 second intervals and a 30 minute duration.

    khain on
  • urahonkyurahonky Registered User regular
    edited April 2010
    Is there a variable I can create that starts at 0, and allows me to increment every time I run the script? So when it hits 60 I can exit the loop?

    urahonky on
  • khainkhain Registered User regular
    edited April 2010
    Someone might be able to give a better answer, but I believe you can use <var name> = value to assign, and to do arithmetic you use expr op1 operator op2.

    Modifying the code xzzy gave
    x = 0
    while [ $x -le 60 ]
    do
      iwlist | grep whatever
      sleep 30
      i=`expr $i + 1`
    done
    

    edit: I'm not that familiar with shell scripting and was using Linux Shell Scripting tutorial to find some of the stuff.

    khain on
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited April 2010
    urahonky wrote: »
    Is there a variable I can create that starts at 0, and allows me to increment every time I run the script? So when it hits 60 I can exit the loop?
    Well, you could expand on xzzy's suggestion and do something like:
    timesRun = 0
    
    while $timesRun -lt 60; do
      iwlist | grep whatever
      timesRun = $timesRun + 1
      sleep 30
    done
    

    Disclaimer: that might not be the exact syntax.

    iTunesIsEvil on
  • BarrakkethBarrakketh Registered User regular
    edited April 2010
    i=0
    while [[ $i -ne 60 ]]; do
      iwlist wlan0 scanning | egrep -o 'Signal level=-[0-9]{1,3} dBm' | egrep -o '\-[0-9]{1,3}'
      (( i++ ))
      sleep 30
    done
    

    Barrakketh on
    Rollers are red, chargers are blue....omae wa mou shindeiru
  • urahonkyurahonky Registered User regular
    edited April 2010
    Modified that a little bit and output all the information directly to a text file so I can upload that to Excel and make a pretty graph. Seriously guys thank you. I wish I had more Linux experience, but I don't. My one quarter of Linux and Windows didn't teach me anything at all except how to do "ls".

    urahonky on
  • BarrakkethBarrakketh Registered User regular
    edited April 2010
    urahonky wrote: »
    Modified that a little bit and output all the information directly to a text file so I can upload that to Excel and make a pretty graph. Seriously guys thank you. I wish I had more Linux experience, but I don't. My one quarter of Linux and Windows didn't teach me anything at all except how to do "ls".

    This is a handy guide and reference for bash scripting.

    When I have to do a lot of text processing I just use Python. If I'm parsing the output of something it's easier to use regular expressions and named groups to get exactly the pieces of information I need.

    Barrakketh on
    Rollers are red, chargers are blue....omae wa mou shindeiru
  • xzzyxzzy Registered User regular
    edited April 2010
    Install cygwin and you can get a unix shell on a windows machine.

    It's 100 times cooler than powershell. But I'm a unix nerd and have been since the mid 90's, so I might be biased.

    xzzy on
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited April 2010
    xzzy wrote: »
    Install cygwin and you can get a unix shell on a windows machine.

    It's 100 times cooler than powershell. But I'm a unix nerd and have been since the mid 90's, so I might be biased.

    I would actually disagree with this. Once you know how to write cmdlets, PowerShell is freakin' amazing. I wouldn't say it's better than a UNIX shell, but just as powerful? For sure.

    GnomeTank on
    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
  • urahonkyurahonky Registered User regular
    edited April 2010
    Bookmarked for future use. Thanks. :)

    And yeah one of my instructors recommended installing cygwin, but I feel completely overwhelmed with command line stuffs.

    urahonky on
  • KrikeeKrikee Registered User regular
    edited April 2010
    So, while I'm waiting 10 minutes for a maintenance window to start I stumbled across this thread, and I noticed the conspicuous lack of Perl in the OP. What's up with that? I am a tier 2 network engineer, and for now I am just scripting SNMP-gets, various SQL queries and I will be broaching actual configuration changes in a week or 2. Any suggestions for making config changes? I was planning to use Expect.

    Krikee on
  • BarrakkethBarrakketh Registered User regular
    edited April 2010
    Krikee wrote: »
    So, while I'm waiting 10 minutes for a maintenance window to start I stumbled across this thread, and I noticed the conspicuous lack of Perl in the OP. What's up with that?
    I, for one, like to be able to read another person's code and easily understand what it does :P Most people who write Perl and publicly post their code seem to do it in the tersest and most obfuscated way they can manage.

    Also, the OP is quotes by people who actually post ITT. Clearly the committee didn't approve.

    Barrakketh on
    Rollers are red, chargers are blue....omae wa mou shindeiru
  • InfidelInfidel Heretic Registered User regular
    edited April 2010
    The Perl coders are underground due to purges.

    You don't come and find them, they'll contact you.

    Or something like that!

    Actually I still use perl for scripting tasks now and then. It does a fine job at its intended purpose, extracting and massaging data. You can even follow proper coding principles, if you want. :lol:

    Infidel on
    OrokosPA.png
  • langfor6langfor6 Registered User regular
    edited April 2010
    Let me know if this isn't the right place and I'll edit this post into obscurity, but...

    I'm a computer science major in my junior year. After this semester I have seven more courses until graduation. As such, I'm starting to get into the meat of my curriculum. We had a fairly lengthy discussion in my OOP course about the speed that people program. Our professor maintains that the best programmers are the fastest ones, which kind of sucked for me because I fall squarely into the slow category.

    For those professionals out there, how big of an impact do you think this will have long term from a career standpoint? I enjoy programming immensely, but I've never been a fast thinker. I've always been more of the sort that has to put in the effort to learn, and I do so at a slow pace relative to my peers. Also, how much do you think speed can be counteracted by experience? There are certainly people around me that have more natural ability, so I'm hoping that practice and exposure can compensate in the long run. I'm interested to hear people's thoughts.

    langfor6 on
  • xzzyxzzy Registered User regular
    edited April 2010
    Good programmers aren't necessarily fast programmers, but fast programmers meet deadlines.

    So it depends on where you work.. if it's always crunch time and your employer is constantly trying to make customers smile, speed will be paramount. If the place is better run, making quality code will be more important.

    xzzy on
  • KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    edited April 2010
    On-time, under budget, correct.

    Choose 2.

    How much experience does your professor have in the industry, exactly? I've worked at places where hitting arbitrary and capricious deadlines was the priority and I've worked at places where getting a fully functional and tested piece of software running was the goal. The second group is where you want to work. It sucks working at places driven purely by schedule pressure, there's no time to do things right and then you get into godawful death marches where half your time is spent just trying to patch over all the shortcuts the "fast" developers did to get things working.

    Now that I'm in charge, I prefer to cut functionality and deliver something that's working correctly and done right rather than slamming shit out.

    And none of the toy programs you do in college are anything like a real-world project.

    So no, just being fast doesn't make you a good programmer.

    Kakodaimonos on
  • InfidelInfidel Heretic Registered User regular
    edited April 2010
    You'll want to be reasonably fast enough.

    Just don't let your work be as sloppy as the fast guy, guess who overall is the better choice then.

    Your best bet is to be the guy that takes his time and gets it right, and make sure your employer realizes it. That also means finding an environment that is compatible with that, not all jobs will want you and you won't want all jobs.

    Probably best for your sanity anyways to find that kind of environment. :) Just harder to find that job.

    Infidel on
    OrokosPA.png
  • DocDoc Registered User, ClubPA regular
    edited April 2010
    http://www.joelonsoftware.com/items/2009/09/23.html

    The whole thing is worth reading, but please pay special attention to this part:
    One thing you have to be careful about, though, is that duct tape programmers are the software world equivalent of pretty boys... those breathtakingly good-looking young men who can roll out of bed, without shaving, without combing their hair, and without brushing their teeth, and get on the subway in yesterday’s dirty clothes and look beautiful, because that’s who they are. You, my friend, cannot go out in public without combing your hair. It will frighten the children. Because you’re just not that pretty. Duct tape programmers have to have a lot of talent to pull off this shtick. They have to be good enough programmers to ship code, and we’ll forgive them if they never write a unit test, or if they xor the “next” and “prev” pointers of their linked list into a single DWORD to save 32 bits, because they’re pretty enough, and smart enough, to pull it off.

    Doc on
  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    edited April 2010
    Well, it depends. I find I can choose to do a fairly poor design in order to do a really quick prototype of something which can be useful to do proof of concepts. And, for problem domains I'm not very familiar with, throwing together a quick sample gives me an idea of what sort of things I missed and what is and isn't done well.

    So, there's advantages to being able to do things quickly, but you still have to put the time in to do a good design or you end up with a mess (I'm still supporting some code I ended up rushing on as a coop student, I'm trying to kill it off but it's been used for too long)

    Phyphor on
  • KrikeeKrikee Registered User regular
    edited April 2010
    Barrakketh wrote: »
    Krikee wrote: »
    So, while I'm waiting 10 minutes for a maintenance window to start I stumbled across this thread, and I noticed the conspicuous lack of Perl in the OP. What's up with that?
    I, for one, like to be able to read another person's code and easily understand what it does :P Most people who write Perl and publicly post their code seem to do it in the tersest and most obfuscated way they can manage.

    Also, the OP is quotes by people who actually post ITT. Clearly the committee didn't approve.
    I know what you mean... I asked for help from one of the software engineers, and the code that was returned to me had to have used every shorthand argument possible. Fairly annoying.

    Krikee on
  • Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    edited April 2010
    GnomeTank wrote: »
    xzzy wrote: »
    Install cygwin and you can get a unix shell on a windows machine.

    It's 100 times cooler than powershell. But I'm a unix nerd and have been since the mid 90's, so I might be biased.

    I would actually disagree with this. Once you know how to write cmdlets, PowerShell is freakin' amazing. I wouldn't say it's better than a UNIX shell, but just as powerful? For sure.

    Powershell also completely violates the principles of least surprise in a few areas.

    It's pretty cool though. The ability to tab through arguments is a pretty magnificent invention.

    Apothe0sis on
  • xzzyxzzy Registered User regular
    edited April 2010
    Infidel wrote: »
    You'll want to be reasonably fast enough.

    You'll get faster as time goes on as well. Whether you got a repository of old code you can C&P from, or you keep a list of common solutions on hand, or you just start to memorize good practices.. eventually you'll speed up.

    Better to focus on writing good code, efficiency comes with time.

    xzzy on
  • bowenbowen How you doin'? Registered User regular
    edited April 2010
    If you're a good programmer, you'll move from bug tester/bug fixer to duct tape programmer.

    99% of the coders in a project are "okay" programmers. The ones that get the best jobs are the ones who tell you you have stupid ideas and the best, but fastest, way to do something is ______.

    It's getting someone in the mindset that it's okay not to use classes and oop for a simple data parser, or something like that, that's the trickiest part. Or that there are better tools for writing scripting engines than trying to write your own C++ parsing tool.

    At the end of the day you will probably end up being a programmer that sacrifices sanity to meet a deadline. The only time I've seen great and perfect code is in academia where there's weeks to write a file parser or lexical analyzer.

    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
  • HalibutHalibut Passion Fish Swimming in obscurity.Registered User regular
    edited April 2010
    I know this discussion started out about how fast you can write code, but it has grown into a "use the right tool for the right job" discussion.

    I would recommend that everyone read The Pragmatic Programmer. It's basically a manual for training yourself to be more efficient. And by that I mean increasing the quality of your code as well as speed at which you can produce it.

    Halibut on
  • bowenbowen How you doin'? Registered User regular
    edited April 2010
    A question for anyone who might know the answer:

    I have a derived class that I'd like to keep the parent class' methods and and such hidden in the derived state. The derived class fills a specific niche in my code. I know in C++ I can set the parent class as private when I inherit, however, in C# I can't do this. Is it even possible?

    Granted I can go around this by using the class internally as a variable but I'd really rather not.

    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
  • InfidelInfidel Heretic Registered User regular
    edited April 2010
    bowen wrote: »
    A question for anyone who might know the answer:

    I have a derived class that I'd like to keep the parent class' methods and and such hidden in the derived state. The derived class fills a specific niche in my code. I know in C++ I can set the parent class as private when I inherit, however, in C# I can't do this. Is it even possible?

    Granted I can go around this by using the class internally as a variable but I'd really rather not.

    I think you're stuck doing that in C#.

    Infidel on
    OrokosPA.png
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    edited April 2010
    As others have said, you become fast over time naturally, but becoming good requires practice. Work on being good, and becoming fast just happens. I don't have to think about most best practices anymore, I just sort of do them. Things like dependency injection, DRY, reusibility and extensibility, just sort of happen when I code at this point, because I've practiced them so much, they might as well be a language construct.

    As a side note, someone in the XNA thread showed a really cool way to approximate Ruby mixins in C# the other day, I thought I would pass it on (I'll go look up his name and edit it in at some point, as I don't want to take credit for his idea):
    namespace MyNamespace {
    
        public interface IMyInterface {
            // Leave this empty
        }
    
        public static class IMyInterfaceImplementationExtensions {
            public static int PowerOf2 (this IMyInterface iface, int i) {
                // Do some stuff here
                return i * i;
            }
        }
    
        public class MyClass : IMyInterface {
            public MyClass () {
                int i = PowerOf2 (10); // This works, returns 100
            }
        }
    
        /* This would also work:
         * var c = new MyClass();
         * int i = c.PowerOf2(100);
         */
    }
    

    Basically, you use extension methods, extending an empty interface, to create mixin/multiple implementation inheritance scenarios. It's not perfect, but it's still pretty cool.

    e: Oh yah, it was Tejs idea. From the XNA thread. Forgot to edit this back in :P

    GnomeTank on
    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
Sign In or Register to comment.