Unofficial Programming Thread IV

Post » Tue Jun 18, 2013 1:05 am

Just to knit-pick, programming languages and deployment/runtime strategies aren't the same thing (although they can end up becoming intertwined). C++ is a language...in theory one could compile code written in that language in a bunch of different ways (including interpreting it at runtime as a script) depending on how good a job programmer did at keeping dependency-specific code encapsulated. The "programming" usage of the language and the compile/deploy/execute usage need not be married.

In general most C++ compilers build native code, so you have to know which platform you're building for ahead of time. Scripting hosts and platforms that use a pre-installed runtime environment (like Java and .NET) are either deployed as-is or are compiled to some kind of pre-binary IL (intermediate language) and are either interpreted/run by a platform-specific scripting host or virtual machine or compiled to a native binary at runtime (JiT). Obviously scripts and common runtime environments have the advantage of portability (sometimes also self-description, reflection, morphing, etc.) while pre-compiling to native code will usually yield the best-performing executables. Those are just rules of thumb, though, and certainly have exceptions (no pun intended).
User avatar
Sian Ennis
 
Posts: 3362
Joined: Wed Nov 08, 2006 11:46 am

Post » Tue Jun 18, 2013 12:45 am


There you go! /tongue.png' class='bbc_emoticon' alt=':P' />
User avatar
Hilm Music
 
Posts: 3357
Joined: Wed Jun 06, 2007 9:36 pm

Post » Mon Jun 17, 2013 11:57 pm

I was thinking more along the lines of
public static boolean toggle(boolean a){        return a == false;}
To stay in line with what SheridanR had mentioned, but that also works (and it's what I'd use -- except that I wouldn't bother making a funtion for something that simple...)
User avatar
Natalie J Webster
 
Posts: 3488
Joined: Tue Jul 25, 2006 1:35 pm

Post » Tue Jun 18, 2013 3:52 am

All the cool kids use XOR these days.
public static boolean toggle(boolean a){		return a ^= true;}
/tongue.png' class='bbc_emoticon' alt=':tongue:' />
User avatar
Ashley Tamen
 
Posts: 3477
Joined: Sun Apr 08, 2007 6:17 am

Post » Tue Jun 18, 2013 10:47 am

Right, the use of a function there would actually be bad.

It adds extra overhead, however minor, that could be avoided by just doing the ! directly.

I prefer simplicity over verbosity, as you know, so yeah. It also looks cleaner to use ! instead of == false. /tongue.png' class='bbc_emoticon' alt=':tongue:' />


I just find that sort of thing to be a bit hard to read for my tastes. /shrug.gif' class='bbc_emoticon' alt=':shrug:' />
User avatar
cheryl wright
 
Posts: 3382
Joined: Sat Nov 25, 2006 4:43 am

Post » Tue Jun 18, 2013 1:40 am

Of course...it's an example of sacrificing readability in the name of a useless amount of optimization. It was a joke, although I do know some programmers that will do that sort of thing. /wink.png' class='bbc_emoticon' alt=':wink:' />
User avatar
Jarrett Willis
 
Posts: 3409
Joined: Thu Jul 19, 2007 6:01 pm

Post » Tue Jun 18, 2013 1:30 am

Quick question that's not directly related to programming (more related to Math/CompSci), but this is the most relevant thread I'm aware of.

Is anyone familiar with derivatives of regular expressions (i.e., Brzozowski's derivatives)? A quick Google search didn't pull up anything useful and my prof did a terrible job of explaining it to us. And by that I mean he just wrote stuff on the chalk board expecting us to know what he was talking about (he does that alot). It seems like magic to me.
User avatar
DeeD
 
Posts: 3439
Joined: Sat Jul 14, 2007 6:50 pm

Post » Tue Jun 18, 2013 7:22 am


I thought this worked in Java too but in c# all you have to do is
booleanVar = !booleanVar;
User avatar
Mrs. Patton
 
Posts: 3418
Joined: Fri Jan 26, 2007 8:00 am

Post » Tue Jun 18, 2013 2:39 pm


Yeah, that's always a risk. A good optimising compiler will do a lot of it for you anyway: not that I'm excusing sloppy code, but I have seen coders who like to be the sort of clever that can cause a maintenance headache...

For simple functions, inlines such as #defines can be quite useful replacements. At the other extreme, I remember working with some source code from "a well-known software vendor" 20 years back and I don't think before or since I've ever seen something that consisted of so many pointless and tangled calls to functions that did nothing other than call other functions. It was bizarre and quite headache-inducing.
User avatar
Roisan Sweeney
 
Posts: 3462
Joined: Sun Aug 13, 2006 8:28 pm

Post » Tue Jun 18, 2013 6:52 am


That's kinda what I feel like whenever I download a piece of code and try to pick it apart. In my opinion if your function, class, whatever doesn't have at least five lines of code in it, it isn't worth using. All it does is make your code difficult to read.

On a different subject, this doesn't directly relate to programming but as an aspiring game developer I found this quite helpful.

http://positech.co.uk/cliffsblog/2010/10/21/how-to-sell-your-game-online-without-using-an-app-store/

I took a glance at http://bmtmicro.com/. It's good to know that when I do decide to sell a game there are services out there that will handle all the DRM and money transactions for me. I really wasn't looking forward to dealing with that stuff myself.
User avatar
JLG
 
Posts: 3364
Joined: Fri Oct 19, 2007 7:42 pm

Post » Tue Jun 18, 2013 12:30 pm

Does anyone have experience writing plugins for XBMC? I tried to follow their tutorial but it did not make sense to me, and it looks like it does use an older version of Python so it should not be that hard. I am looking to write a couple for some image sites I use but cannot seem to wrap my head around it and am looking for some help if possible.
User avatar
Guy Pearce
 
Posts: 3499
Joined: Sun May 20, 2007 3:08 pm

Post » Tue Jun 18, 2013 7:03 am

I get your point but that kinda depends. Some of my interface class definitions are really short. They are intended to work as a sort of code injection mechanism into a bigger class. They can have just the constructor, virtual destructor and a single action function. It's pure abstract, so there's no implementation in it and can really only consists of 5 lines. Not even the implementations that inherit from it are much more complex than that. Sometimes they need to be. The benefit is that I don't need to check some input mode variable within a tight loop, and instead I can inject the piece of code outside the loop.

When you add factories, multiple inheritance, managed c++ and all into this, yes, the resulting code can be a pain to read. You can only figure it out by debugging when not even the IDE can't help you out. It would just point you to the pure abstract interface class and you'd have to search for the references. At least I haven't found a proper way to interpret this kind of code in Visual Studio 2008.

I bet I could use a function pointer to plug in some changing functionality into a class too, but in my opinion that would be more difficult than taking advantage of some class with the implementation and instantiating that inside a smart pointer.. Note to self, document your code better.

Most of UI related functions can also consist of a single line as far as I've seen. You click a button, and it sets a local variable. Then you click OK and it runs some action function with possibly a few more lines. However, that's mostly because of how the programming interface connects the entities like buttons to functions through some event mechanism.

Can we agree on that the target length for a function would be something between 5 to 50 code lines to keep it maintainable? Longer functions are again less readable in my opinion.
User avatar
Mandy Muir
 
Posts: 3307
Joined: Wed Jan 24, 2007 4:38 pm

Post » Tue Jun 18, 2013 9:28 am

*draws pentagram on ground*
*casts spell of thread revival*
IT LIVES!!!!

Okay... I am getting back into C, and my main problem is I can't for the life of me find a good video tutorial. I find either video tutorials that give you no background to the commands whatsoever, or I find hour long videos narrated by someone that might as well be Microsoft Sam. Does anyone know a good place for programming tutorials in general? I have found that cprogramming.com has a decent text-based one, but I would prefer a video based one.

I tried this once before, but the methods it taught me involved some really bad practices including system ("PAUSE") and other things.

If you can't help with that one, could someone help me with understanding boolean operators ( stuff like AND, OR, NOT.)? It is a bit fuzzy for me with the true and false outputs. IIRC, anything not 0 is considered true, and 0 is false. Is that right?
User avatar
Kahli St Dennis
 
Posts: 3517
Joined: Tue Jun 13, 2006 1:57 am

Post » Tue Jun 18, 2013 2:29 am


That's correct, yes; though there's an exception which is that things like system calls often return a -1 to indicate a problem rather than 0, so something to watch out for.

In terms of tutorials, I found one of the most effective means of learning C was to dig through the Unix source code to see how some of the more simple system commands did stuff.
User avatar
Quick Draw
 
Posts: 3423
Joined: Sun Sep 30, 2007 4:56 am

Post » Tue Jun 18, 2013 8:34 am

So I found this: http://www.codecademy.com/#!/exercises/0

Its pretty neat.
User avatar
Glu Glu
 
Posts: 3352
Joined: Sun Apr 01, 2007 5:39 am

Post » Tue Jun 18, 2013 4:25 am

Not exactly sure what you mean by that "PAUSE" bit, but it doesn't really matter what it is that you're writing as long as you're learning all of the right principles.

When I learned C, my dad had me use a development environment named Turbo C. It was running on an old DOS box, so my system resources were very limited by modern standards, but it was still an excellent platform to learn in because it was very simple. When a program started, the OS would just hand it control of the entire system, meaning that from that point forward it was just you and the machine. Very fun. In fact, I only started encountered problems with headroom when I started writing things like Wolfenstein 3D clones. /tongue.png' class='bbc_emoticon' alt=':P' />

That's right. In one sense, however, the return value of a function can represent what's called an error code, and a return value of zero actually means "no error." It's an important distinction to make when you start making implicit references to function returns.
User avatar
kyle pinchen
 
Posts: 3475
Joined: Thu May 17, 2007 9:01 pm

Post » Tue Jun 18, 2013 12:06 am

So I'm doing the courses on the website I mentioned earlier. The goal here is to print the value of "multiplied":


But I keep getting the error:
Make sure you log the value you get from timesTwo(). And it should be 8!


What am I missing?

EDIT: I got it.
User avatar
Yvonne
 
Posts: 3577
Joined: Sat Sep 23, 2006 3:05 am

Post » Tue Jun 18, 2013 7:52 am

So I'm thinking about throwing together a simple GUI to display some data I'm storing in some structs which can themselves contain an arbitrary number of nested structs.

I've been looking into things and can't really decide between wx or GTK+. Can anyone give a recommendation or help break down the differences more?
User avatar
Lauren Denman
 
Posts: 3382
Joined: Fri Jun 16, 2006 10:29 am

Post » Tue Jun 18, 2013 10:59 am

https://github.com/EvilTosha/labirinth/blob/master/lab2.sh Yup.
User avatar
kirsty williams
 
Posts: 3509
Joined: Sun Oct 08, 2006 5:56 am

Post » Tue Jun 18, 2013 10:08 am


I'll have to give that a try later! Nice to see a bit of that sort of creativity again. /smile.png' class='bbc_emoticon' alt=':)' />
User avatar
Madeleine Rose Walsh
 
Posts: 3425
Joined: Wed Oct 04, 2006 2:07 am

Post » Tue Jun 18, 2013 4:10 am

http://sed.sourceforge.net/local/games/. Huh. Don't know which surprises me more. A game in sed or a game in bash.
User avatar
Heather Dawson
 
Posts: 3348
Joined: Sun Oct 15, 2006 4:14 pm

Post » Tue Jun 18, 2013 11:51 am

Is there anyone who knows C# pretty that would like to look over some code for me? I just wrote a small application to go through a user's Steam installation folder and look for allt he DirectX, Visual C++ runtime, and XNA setups files and remove them (if the user wants). It appears to work on my machine but as we all know that is like testing in a bubble. I don't want to put this out even as an alpha just yet until I get a code review, even from a non professional, because I don't want to have missed something and cause a user's data to blow up. I could put a warning but we all know how well people listen to those.

If anyone is interested in testing this or looking at the code please PM me. The code seems safe to me but I can't be responsible for lost game files. It should ONLY affect the above listed files and nothign else. No steam data is gathered at all either.
User avatar
Queen Bitch
 
Posts: 3312
Joined: Fri Dec 15, 2006 2:43 pm

Post » Tue Jun 18, 2013 11:56 am

I plan to use Mercurial to do my version control so would you all suggest I host the projects I make on Google Code or SourceForge? I already have one on Google so may be better keeping it all in one place but I feel I should ask anyways. I plan to always GPL the code or maybe BSD license it and I know Google has restrictions.
User avatar
Siidney
 
Posts: 3378
Joined: Fri Mar 23, 2007 11:54 pm

Post » Tue Jun 18, 2013 9:30 am

This is a really trivial question that doesn't deserve a thread of its own, so while it's not exactly about programming, it's close enough (?) ...

https://twitter.com/1pld/status/324368684896382978? And little hearts and hands and actual images of smiley faces?
User avatar
Matthew Barrows
 
Posts: 3388
Joined: Thu Jun 28, 2007 11:24 pm

Post » Tue Jun 18, 2013 2:20 am

As he said, Unicode. Specifically Unicode special characters and symbols. Wikipedia has lists of these that one can just copy/paste into most text-fields. Alternatively most rich-text editors should allow you to add them with an insert symbol option. Or you could learn the different codes and add the symbol by typing Alt+the four digit code in question.
User avatar
Anne marie
 
Posts: 3454
Joined: Tue Jul 11, 2006 1:05 pm

PreviousNext

Return to Othor Games