1. Broken Forum will be down for a few hours on Saturday morning (US Central time) for server upgrades. EVERYONE PANIC.

The Programming Thread

Discussion in 'Technologics' started by Charles, Jan 5, 2012.

  1. JoshV Keeper of the Elemental Materials

    Oh, I just saw this: http://aigamedev.com/open/news/ctf-competition/

    It's kind of neat, sort of like the other AI challenges, but more FPS oriented. I have a week off coming up, but unfortunately I will be doing a roadtrip, or I might find this to be pretty fun to try.
    Elyscape likes this.
  2. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    GOD DAMN IT GOOGLE SWITCH TO JDK7. I WANT STRINGS IN SWITCHES.

    RAGE!!!!

    edit: I've finally swapped my basic functional agent model to jdk6 so that it can run on google app engine. End goal is to throw up a portal and be like "hey guys, here's the model now fuck with the output and let's see what we get results wise." Economics for all the motherfuckers up in heah. If I'm lucky I'll have that done in two weekends, and then I can actually implement the first model (this one is a simple eval %, more complex shit would be more complex.

    End end goal, scripting language for tasks and evaluations so that the model can be changed without fucking around in Java since that's all firewalled off from the thread related aspects. Messages can already be set in a config.

    edit:

    Fuuuuuuuuuuuuck. I guess I get to find how efficient (as opposed to readable and easily comprehended) my model is at the moment.
    Elyscape likes this.
  3. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    I did not know that you could use static imports to import just a function. I learned this thanks to Objectify http://code.google.com/p/objectify-appengine/wiki/Setup#Enable_static_imports_in_Eclipse

    All you have to do is import static BlaBlah.foo(); and just like that you can be storing women in binders without needing to type out the full name.

    I'm sure everyone else already knew this and I'm just retarded but fuck everyone, I am so pleased.

    edit: MAVEN IS THE BEST THING EVER.

    edit:

    this is apparently legal:
    for(int i=0; results.next(); i++)

    I can't think why it wouldn't be and I'd have been really frustrated right now if it wasn't but it still blows my mind.
    Nick likes this.
  4. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    Can we make fun of Java now, or did we already do that? What language haven't we made fun of yet?
    Elyscape likes this.
  5. BaconTastesGood Hard Cider Gal

    Location:
    North Carolina
    Took three hours to hunt down what turned out to be a compiler bug in release mode for a console. Compiler bug diagnoses are like lupus -- easy to blame, but never actually the cause. I believe this may be the fourth legit compiler bug I've found in my career.
    Marcin, Damien Neil, Aeon221 and 4 others like this.
  6. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    I've found 1 code generation error in my career. That was fun.

    TurboC++ 3.0.

    static Thing* p = new Thing();

    Would create a new Thing every 65536 calls.
    cnahr and Elyscape like this.
  7. Linoleum Despondent Fancybear

    Was it the SN or GH compiler?
  8. MightyMooquack Worked The System

    I had one a while back which ended up being a bug in the platform's libc.

    Recently I've returned to an old project written using pygame, which I'd set aside after getting bogged down in implementing a UI framework. Now I'm back at it, and have written what is essentially an entire GUI implementation. Good lord is this some tedious stuff.

    The thing with pygame is that it just gives you a window with some pixels in it, along with telling you which pixel a mouse event happened on. If you want windows or buttons or any sort of widgets, they need to be implemented on top of that. While there may or may not be existing frameworks for this sort of thing, I've opted to write my own.

    And it works pretty well so far. Last night I got mouse event handling to the point where I can recognize click-and-drag actions. That will allow me to implement primitives like scrollbars, and to properly implement buttons. (Consider the logic involved with a button: Press and hold the mouse over a button, and it changes to its "pressed" form. Then drag the mouse off the button and release: The button's appearance returns to normal, but it doesn't perform its action. Now, for bonus points, do all of that while also correctly handling the app losing focus while the button is pressed.)

    Anyway, it's a project.
    Elyscape likes this.
  9. BaconTastesGood Hard Cider Gal

    Location:
    North Carolina
    [IMG]
  10. BaconTastesGood Hard Cider Gal

    Location:
    North Carolina
    I would highly recommend doing things like this as an immediate mode GUI. Much faster to get up and running and easier to maintain/extend.
    Elyscape likes this.
  11. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    https://github.com/douglascrockford/JSON-java

    And for my first act of evil, I shall break the terms of the license and use it anyway! MUAH HA HA HAHA HAHA HAHA!
    lesslucid, extarbags and Elyscape like this.
  12. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    I've used PGU to add some windowing and stuff on top of my pygame thing. It's not a game really, I just needed a joystick handler. Talk about a fugly GUI though. Yech. Made my Windows Forms programs look like masterpieces of design.
    Elyscape likes this.
  13. Nellie Keeper of the Elemental Materials

    It's only taken me two years, but I finally have a SQL server and visual studio. I'm blowing out the cobwebs and starting to put some foundation work down around both database and application but where I think I have both a gap and a mental block is around linq. The DBA side of me is very wary of giving that much control over the data[base] to the application and while the code monkey side of me can see the potential of it I'm unclear at the moment as to where that dividing line is of using traditional ADO interaction with the DB and where I might best use linq to full effect.

    I've done a fair bit of reading up but a inevitably a lot of the articles I've come across so far are fairly abstract in nature. I'm just wondering if anyone has any recommendations on some good foundation material regarding use of linq, or not, as the case might be.

    Just as an example of where I think linq might be useful based on what I've seen so far is that, for reasons I won't bore people with, I have to extract several million rows of data into several .csv files for loa d into another system. I took the traditional route of using a data reader and a bunch of code to produce the files but it seems like linq would give an easier and more efficient means to achieve the same, albeit pointless, aim.
    Elyscape likes this.
  14. mkozlows Worked The System

    So, two things:

    1. "Linq" isn't what you mean to talk about here. Linq is Microsoft's name for a bunch of functional programming and deferred processing features added to the .NET Framework, and C# syntax sugar that makes them look vaguely familiar to SQL users.[Footnote 1] It has nothing in particular to do with databases, despite the vaguely SQLish syntax. There was briefly an object-relational mapper called "Linq to SQL" (which some people called "Linq" imprecisely and confusingly), but that's dead technology that you shouldn't use. Microsoft's current ORM is Entity Framework. For querying purposes, it does support "Linq to Entities," which uses Linq features -- but you could use Entity Framework without using that, I believe, and your real question is whether or not you should use an ORM.

    2. So to address that question: You should use an ORM, yes. The productivity vs. hand-writing DB access code is huge, literally order of magnitude improvements. Not to mention the massive wins in testability and maintainability. And you're worried about DB performance, but as long as you don't do egregiously stupid things (a common rookie mistake is the n+1 query situation -- you do a query that returns n objects, and then when looking at each object, you look at a lazy-loaded collection that requires another DB query for each object; this can be easily avoided as long as you know you want to avoid it), the performance will be fine.

    In fact, there are a lot of situations where using an ORM can actually improve performance vs native SQL. Consider a case where you want to do a complex update statement that depends on doing aggregate operations on a half-dozen joined tables, say. You can write that as a single "pure" SQL update statement, and it'll be very CPU-intensive on your database, and your locks might end up escalating in ways that cause problems for you. But if you do it with an ORM, you'll do all the complex calculations on the (cheap, scalable) web server, and then all that the DB gets is a series of super-straightforward "update t set f = z where id = n" statements.

    Doing raw data-access/SQL these days is something you should treat like people used to treat dropping into assembler from C -- a specific optimization that you do when you have a clear, demonstrated need for it, and not before.

    Footnote 1: To demonstrate this, let's say that given a list of books, you wanted to get the title and ID of all the books that are in the SF genre. This is a simple thing to do. Using standard functional operators in JS:

    bookList.filter(function(b) { return b.genre === 'SF' }).map(function(b) { return {id: b.id, title: b.title}; });

    Right? And so that's straightforward. But it scares people who haven't had exposure to functional programming, because it requires them to think at a higher level of abstraction than they're used to -- they totally want to write that as a for loop with an if statement.

    But so Linq tricks them, because of course they've written SQL, so it just renames the operators to SQL-like operators:

    booklist.Where(b => b.genre == 'SF').Select(b => new {Id = b.Id, Title = b.Title});

    And people will look at that and not be freaked out, because it looks familiar. Even though it is exactly the same as the traditional functional methods. And of course, C# also has that syntactic sugar that makes it look even more SQLy:

    from b in bookList
    where b.genre == 'SF'
    select new {I = b.Id, Title = b.Title}

    Same exact code as the JS version, utterly classic and traditional functional operations, but suddenly it just looks like a tweaked-up SQL query to people, and they'll use it habitually where they'd never dream of using the traditional functional stuff.
    Aeon221, L'Oncle, AaronSofaer and 2 others like this.
  15. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    I found out two things very recently:

    Thing 1: You can use the 'native' thingy to write native code in a .java file. eg: public static void native usingNativeCode()

    And as on google app engine native code is JavaScript, fuck all the interpreters for JSON. I can just use javascript's eval() to translate it into an object inside my existing program and then make it rain Java objects.

    Aww yiss!

    Thing 2: GWT is Super AJAX.

    I didn't get that before because I was just using the Google App Engine stuff (which is awesome and makes me happy). Now that I need a fancy UI I was like "well I'll do AJAX" and then I was like "wait wut GWT Designer Plugin for Eclipse wut is dis OOOOOOOOOOH *spooge*" and now it's like the Netbeans Swing visual designer but sexy.

    <3 google, I wish they owned Java and smelly Oracle owned something suck like Python (fuck your whitespace loving fucked face you fuck). I should probably learn Go because I bet five bucks Go is gonna replace Java in Google's heart and then Java will just be suck and awful and pain.

    Point of interest, GWT is bi(directional).
  16. Elyscape Hatoful Pigeon

    Location:
    San Jose, CA
    This is incredibly unsafe. Please don't do it. There's a reason that people use interpreters.
    Afti likes this.
  17. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    Why you gotta kill my dreams bro?
    Elyscape likes this.
  18. Elyscape Hatoful Pigeon

    Location:
    San Jose, CA
    If it's provided (and it probably is), you can use JSON.parse(), which basically does the same thing without being ridiculously insecure. Unlike eval(), JSON.parse() doesn't allow for the execution of arbitrary code.
  19. MightyMooquack Worked The System

    Oh, them's fightin' words. We are throwing down. I can only respond to this thusly: Nuh-uh!

    The whitespace thing is probably the most common objection to Python, but I don't really understand why people get worked up about it. You indent your code in other languages, right? So what's the difference? Python doesn't particularly care how you indent, so long as it is consistent. And given that Python ignores whitespace while you're inside of any sort of parentheses or braces (function calls, list or dict literals, and so on), it doesn't really impact your ability to format your code.

    It's more forgiving than I think people assume. (You can only really get into trouble if you mix tabs and spaces, and even then only if you do so assuming a hard tab represents something other than an 8-space tab-stop.) Reactions like yours always seem irrational to me, and I'm interested in whether you can cogently explain it.

    (Go is pretty cool, though.)
    Nick, cnahr, BaconTastesGood and 2 others like this.
  20. rossm Hivemind Coordinator

    Location:
    Louisiana
    I prefer curly braces for scope over no curly braces. I find it easier to scan code visually when compared to plain indents. I think using positive space rather than only negative space makes it easier. I realize this is only because I'm used to it.
    Elyscape and Aeon221 like this.
  21. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    Python and similar whitespace obsessed languages are the exception, not the rule. Clearly you should be justifying your love rather than me justifying my hate!
  22. BaconTastesGood Hard Cider Gal

    Location:
    North Carolina
    Love never needs to be justified.
    Marcin, chequers and Talisker like this.
  23. MightyMooquack Worked The System

    If you can leave out the curly braces without losing information (since the same information is recorded in the indentation of the code), then the curly braces are redundant, and are effectively just noise. Leaving them out improves code clarity, saves vertical space, simplifies the writing of code, and just plain looks better.

    I will acknowledge the major weakness of Python's syntax, which is poor anonymous function syntax. There are workarounds (using named functions, using lambdas when they are all you need), but there's no way to get a code-suite-as-expression. Even so, the benefits of the syntax outweigh this concern.
    Nick and chequers like this.
  24. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    I could compromise if the brackets were something I could include that caused the compiler to LEAVE WHITESPACE ALONE. Because then it'd be totally optional and cool and I could dig that and then get back to the important shit which is obviously never curlies/whitespace.

    Unfortunately that is not the case.
  25. JoshV Keeper of the Elemental Materials

    Funny, just last night I started messing with an old Unity project, and doing the GUI. Immediate mode is what they have and it is simple, but I do sometimes wish I could just use XAML or something a little deeper. Though I guess they're going to have some new fangled UI soon, so I'm just going to plow through and put in some placeholder stuff for now.
    Elyscape likes this.
  26. MightyMooquack Worked The System

    What are you doing that you need it to leave the whitespace alone?
    Elyscape likes this.
  27. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    [IMG]
    lesslucid, JoshV and Elyscape like this.
  28. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    Have you seen ever right-justified love? So many reference to Jesus, I just don't get it.
    Aeon221 likes this.
  29. mkozlows Worked The System

    Here are three benefits to Python's approach with whitespace:

    1. Forcing code into a particular format eliminates tedious programmer argumentation about how it should be indented.
    2. Making the visual structure be identical to the logical structure prevents mis-indentation from confusing readers of the code, because the reader and the parser are looking at the same thing.
    3. Significant whitespace is such a minor cosmetic thing that when people focus on it, you can tell they haven't really used Python enough to have meaningful opinions about it.
    lesslucid, Nick, Talisker and 4 others like this.
  30. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    I program Python infrequently. I also program it like an old-skool C++ programmer, which, err, I guess I am. Regardless, I find myself easily able to no back and figure out what I was thinking (and where I was in my never-ending Python otj learning experience). The white space thing is really not that hark to grok (once I figured out was "pass" was....)
    Elyscape likes this.
  31. chequers Oh, Come On

    Location:
    Sydney
    What do you mean? I'm an atheist.
    lesslucid, cnahr and Elyscape like this.
  32. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    So I fired up Visual Studio for the first time 2 year today. I installed the new ALL CAPS edition. Then I proceeded to hack on some MFC sample programs (and I haven't done MFC in a decade).

    You know what, except for the ALL CAPS, not much has changed. Sure, Intellisense works better than the last time I used Visual C++ on Windows (good luck parsing these C++ templates!), but it's still the same shit that it ever was.

    Except in ALL CAPS. Oh shit, we're all Metro now, so we have no menu gradient, so no one can find the menus, so FILE EDIT VIEW MOTHERFUCKERS.

    Oh, and the supporting WTF goes to the Visual Studio website.

    http://www.microsoft.com/visualstudio/eng/visual-studio-update

    HERES A PICTURE OF AN ENGINEER OR A DIAGRAM OR SOMETHING WITH 5 LINE OF TEXT IN A POPDOWN MENU ON THE SIDE.

    Wait, that wasn't in all caps. My bad.

    I like C++. I just don't like writing GUIs in C++. It's like fighting through mud while you try to figure out if you should use std::string, CString, CComBSTR, or whatever, and then you realize that all the functions just take pointer to TCHAR and then you have to deal with Unicode and then you just fall back to const char* and hope no one ever runs this toy program on a non-US computer.
    Elyscape and JoshV like this.
  33. Quackers Magister Mundi Elyscape

    I like Objective C so far. Does that make me a bad person?
  34. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    No, it makes you a fez-wearing elitist.
    vyshka, Carnifex and chequers like this.
  35. JoshV Keeper of the Elemental Materials

    I'm not sure what you mean by all the ALL caps stuff, are you talking about Visual Studio 12? I don't recall the all caps.


    On the other hand, fuck strings in C++. Especially any kind of wonkiness with going to/from different types of strings. And GUIs, man, so much easier in C#.
    Elyscape likes this.
  36. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
  37. MightyMooquack Worked The System

    BUILD IT MOTHERFUCKER CAN YOU CLICK IT

    Just as an update, I've abandoned my earlier pygame project in favor of just throwing PyQt4 at it. It is rather a lot less work. While my project was coming along nicely, each step of progress only put further emphasis on how hilariously doomed the project as a whole was.

    There's a widget in Qt called a QGraphicsView, which gives you a pannable view into an arbitrary "scene" of graphical elements (shapes, images, text, etc). This is nearly ideal for a turn-based strategy game, following a bit of tweaking.

    Supposing a game like Civ, where you have a world map which wraps left-to-right (a cylindrical projection), this widget is not sufficient. There is no direct way to make it wrap. My first success was to simulate the effect by cheating: I render two identical maps adjacent to each other, and simply teleport the position of the view when it gets too far to the left or right. If you get the arithmetic right (and limit the width of the view to the width of the map), the effect is entirely seamless. My next efforts have been to make the arrow keys and mouse behave in the way that I want.
    JoshV and Elyscape like this.
  38. cnahr Hard Cider Gal

    By the way, XPav is using the VS2012 Color Theme Editor to restore the nice blue color scheme a sane person would use, instead of the brutally ugly monochrome color of the normal release version.
    JoshV likes this.
  39. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    I love allcaps alltoo well but even I can't allcap allthe time.

    Microsoft why you so zany!
  40. AaronSofaer Magister Mundi Elyscape

    "This problem would be best solved with recursive forking!", said nobody who knew what he was talking about ever.

    (To clarify, I am referring to myself.)

    It did actually work, but only because the compiler does magic. It turns out that forking is not, however, the preferred way to do parallelism, and I am a bad person who does bad things.