Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

masher
Posts: 821
Joined: Tue Oct 23, 2007 11:07 pm UTC
Location: Melbourne, Australia

Re: Coding: Fleeting Thoughts

Postby masher » Thu Oct 15, 2009 5:51 am UTC

rrwoods wrote:
You, sir, name? wrote:It probably implicitly does .toString() somewhere. Like evaluating as

s = s.toString().append("foo")

Not quite, since "s." should throw NullPointerException. But you're close. There is a static method String.valueOf(Object obj), that reads exactly as follows:

Code: Select all

return (obj == null) ? "null" : obj.toString();

It's called implicitly.


If I decompile with Jad, I get:

Code: Select all

        String s = null;
        s = (new StringBuilder()).append(s).append("foo").toString();
        System.out.println(s);

The StringBuilder documentation says "If the string is null, then the four characters "null" are appended"

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: Coding: Fleeting Thoughts

Postby Cosmologicon » Thu Oct 15, 2009 7:22 am UTC

As an exercise, I implemented a binary search tree in C++. Now I want to try it out. What are these things good for? I can use it like a set or an associative array, of course. I've used associative arrays plenty before, but never as the primary data structure in a problem. I've already sorted a bunch of integers. Anything better?

Searching for examples of trees online only shows how to implement them, not how to use them effectively. Searching for uses of associative arrays only shows really trivial examples, like age["Joey"] = 11 and so on. Any ideas?

notallama
Posts: 236
Joined: Fri Jun 01, 2007 4:28 pm UTC

Re: Coding: Fleeting Thoughts

Postby notallama » Thu Oct 15, 2009 7:49 am UTC

binary search trees are basically good for teaching you how a binary search tree works.
generally, you'll want a self balancing one. maybe a red black tree or a skip list or something.

but anyways, you can use it as a priority queue. or you can extend the idea a bit and get an kd-tree, which is useful finding nearest neighbour and intersections in 3d.

Outchanter
Posts: 669
Joined: Mon Dec 17, 2007 8:40 am UTC

Re: Coding: Fleeting Thoughts

Postby Outchanter » Thu Oct 15, 2009 8:46 am UTC

Cosmologicon wrote:I've used associative arrays plenty before, but never as the primary data structure in a problem.

Associative arrays / maps / dictionaries have many uses. For one thing, they can often be trivially modified to implement sets.

For graph representations, computer science students are often taught that adjacency matrices and edge lists are alternatives with different trade offs. It's actually easy to combine most of the advantages of both, though - just use edge lists, but replace the lists with sets, implemented using an efficient set data structure.

Dictionaries are also useful for memoizing, and very important in compilation.

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: Coding: Fleeting Thoughts

Postby Cosmologicon » Thu Oct 15, 2009 9:01 am UTC

Ah, memoization, yes, that's a great idea. I've used memoization before for a Nim playing program that uses recursive calls. I'll see how my implementation does.

If it does okay on that, maybe I'll give a kd-tree a shot.

Thanks to both of you!

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: Coding: Fleeting Thoughts

Postby Emu* » Thu Oct 15, 2009 12:32 pm UTC

masher wrote:
rrwoods wrote:
You, sir, name? wrote:It probably implicitly does .toString() somewhere. Like evaluating as

s = s.toString().append("foo")

Not quite, since "s." should throw NullPointerException. But you're close. There is a static method String.valueOf(Object obj), that reads exactly as follows:

Code: Select all

return (obj == null) ? "null" : obj.toString();

It's called implicitly.


If I decompile with Jad, I get:

Code: Select all

        String s = null;
        s = (new StringBuilder()).append(s).append("foo").toString();
        System.out.println(s);

The StringBuilder documentation says "If the string is null, then the four characters "null" are appended"



Starting with a StringBuilder initialised with "" is probably a better idea since Strings are immutable.
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

User avatar
spudtheimpaler
Posts: 181
Joined: Thu May 24, 2007 11:57 am UTC
Location: München

Re: Coding: Fleeting Thoughts

Postby spudtheimpaler » Thu Oct 15, 2009 3:26 pm UTC

Emu* wrote:...
Starting with a StringBuilder initialised with "" is probably a better idea since Strings are immutable.

Or if you have a good idea of the size, initialise with the size (plus a chuck of contingency if you're not 100%) as initialising StringBuilders or StringBuffers I think starts with an internal array of size 16 which can quickly grow and then you're internally resizing all the time. If you start it with a reasonable size you can probably get away with no resizing, or maybe only the once, and it's no harm slapping the .append on the newly created, reasonable sized SB.
Fueled by tea and bad maths since 1983...

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Coding: Fleeting Thoughts

Postby Random832 » Thu Oct 15, 2009 5:58 pm UTC

Could take a page from .net - a function that takes a variadic list of strings, counts them all up, and then (effectively - this is done at a lower level with a mutable String in .net) makes a stringbuilder exactly big enough for all of them and puts them all in the right place. This is how str+str+str is implemented in C#. Should be slightly better performance in many situations than chaining concats on an undersized sb.

Of course, .net strings maintain a length count. Don't know if java strings do.

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: Coding: Fleeting Thoughts

Postby rrwoods » Thu Oct 15, 2009 6:07 pm UTC

Random832 wrote:Of course, .net strings maintain a length count. Don't know if java strings do.

Code: Select all

public final class String
    implements java.io.Serializable, Comparable<String>, CharSequence
{
    /** The value is used for character storage. */
    private final char value[];

    /** The offset is the first index of the storage that is used. */
    private final int offset;

    /** The count is the number of characters in the String. */
    private final int count;

    /** Cache the hash code for the string */
    private int hash; // Default to 0

Yep.
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: Coding: Fleeting Thoughts

Postby MHD » Fri Oct 16, 2009 2:21 am UTC

Just started coding C. I know C++ already. Thought I'd utilize the mystery-ness of pointers to make a soft-typed, doubly linked list. My compiler disagrees. With segfaults.
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"

User avatar
Briareos
Posts: 1940
Joined: Thu Jul 12, 2007 12:40 pm UTC
Location: Town of the Big House

Re: Coding: Fleeting Thoughts

Postby Briareos » Fri Oct 16, 2009 2:28 am UTC

MHD wrote:My compiler disagrees. With segfaults.
That's always the way. I have in other threads embraced the wisdom of adding "-Werror" to one's CFLAGS. Making the compiler more disagreeable makes it more likely that your runtime will be agreeable. Not that this has any application to your particular segfaulting problem -- I am just a fan of compilers.
Sandry wrote:Bless you, Briareos.

Blriaraisghaasghoasufdpt.
Oregonaut wrote:Briareos is my new bestest friend.

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: Coding: Fleeting Thoughts

Postby rrwoods » Fri Oct 16, 2009 6:44 pm UTC

Random Eclipse question -- When I double-click a .cmd file from Eclipse, it uses Eclipse's install directory as the working directory. Is there anyway to tell it to use the directory the file is contained in as the working directory?
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

User avatar
rat4000
r/ratsgonewild
Posts: 451
Joined: Mon Feb 09, 2009 7:51 pm UTC

Re: Coding: Fleeting Thoughts

Postby rat4000 » Fri Oct 16, 2009 8:33 pm UTC

The only language I know (have done a project of reasonable size in) is C++. That project was just completed; I intend to go on projecting in it, but I feel somewhat like a construction worker with one leg and one arm, if you get my meaning.

What do I learn next?

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Fri Oct 16, 2009 8:34 pm UTC

rat4000 wrote:I don't know any functional langugae, though I have done a bit of Haskell in the past. In fact, the only language I know (have done a project of reasonable size in) is C++.

What do I learn next?

COBOL
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: Coding: Fleeting Thoughts

Postby ash.gti » Fri Oct 16, 2009 10:02 pm UTC

I wonder how often in OO programming you want to go both up and down the inheritance tree to look up a method...
# drinks WAY to much espresso

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Fri Oct 16, 2009 10:03 pm UTC

rrwoods wrote:Random Eclipse question -- When I double-click a .cmd file from Eclipse, it uses Eclipse's install directory as the working directory. Is there anyway to tell it to use the directory the file is contained in as the working directory?

You can right-click it to open the containing folder in the shell, then run it from there.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

elminster
Posts: 1560
Joined: Mon Feb 26, 2007 1:56 pm UTC
Location: London, UK, Dimensions 1 to 42.
Contact:

Re: Coding: Fleeting Thoughts

Postby elminster » Mon Oct 19, 2009 4:07 am UTC

Intel's VTune is a damn awesome profiler. That is all.
Image

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: Coding: Fleeting Thoughts

Postby rrwoods » Mon Oct 19, 2009 2:05 pm UTC

headprogrammingczar wrote:
rrwoods wrote:Random Eclipse question -- When I double-click a .cmd file from Eclipse, it uses Eclipse's install directory as the working directory. Is there anyway to tell it to use the directory the file is contained in as the working directory?

You can right-click it to open the containing folder in the shell, then run it from there.

Hmm... Not seeing it.
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Tue Oct 20, 2009 1:41 am UTC

Oh, I'm an idiot. I read that as a .bat file instead of a .cmd file.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
'; DROP DATABASE;--
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy
Contact:

Re: Coding: Fleeting Thoughts

Postby '; DROP DATABASE;-- » Wed Oct 21, 2009 6:06 am UTC

I'm really starting to love Lua. It's one of those languages that's so simple, you get a little miffed at its lack of basic constructs like switch(), until you realize that construct is just an abstraction of something simpler (i.e. a table of functions).

What I really like about it though is it's just so easy to integrate into a C/C++ program, and there are so many libraries available (which can be loaded at runtime) to extend it. There's one that gives you access to pretty well all of GTK. So I can do all the actual logic and heavy work in a C "backend", while handling all the GUI in Lua. It's like perfect MVC, and so easy!
I've been working on a 3D map design program, and the GUI code in C was huge and ugly. All I really had to do was strip it down to an interface through which Lua scripts can control the model and camera and save/load files, and let those scripts set up a GUI around it. So much cleaner and simpler. As a bonus, it being interpreted means you get a completely customizable GUI, and full-blown scripting/automation through those same interfaces.

And you just have to love replacing page after page of this:

Code: Select all

Button = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
gtk_box_pack_start(GTK_BOX(Box3), Button, FALSE, FALSE, 0);
gtk_signal_connect(GTK_OBJECT(Button), "clicked",
   (GtkSignalFunc)cMainWindow_CamPosZero_Click, this);

//...

void cMainWindow_CamPosZero_Click(GtkButton *Button, gpointer Win)
{
   MainWindow *_this = (MainWindow*)Win;
   _this->Cam.SetPosition(0, 0, 0);
   gtk_entry_set_text(GTK_ENTRY(_this->XPosBox), "0");
   gtk_entry_set_text(GTK_ENTRY(_this->YPosBox), "0");
   gtk_entry_set_text(GTK_ENTRY(_this->ZPosBox), "0");
   _this->NeedRedraw = true;
}
With this:

Code: Select all

this.ResetPosButton = gtk.button_new_from_stock(gtk.GTK_STOCK_CLEAR)
HBox:pack_start(this.ResetPosButton, false, false, 0)
this.ResetPosButton:connect("clicked", function(button)
   this.XPosBox:set_text(0)
   this.YPosBox:set_text(0)
   this.ZPosBox:set_text(0)
   MainWindow_SetCameraPos(this.MainWindow, 0, 0, 0)
   MainWindow_Redraw(this.MainWindow)
end)


(I need to rework that to make MainWindow actually an object; this.MainWindow:Redraw() makes much more sense... >_> and maybe SetCameraPos should automatically update the textboxes as well. Still a work in progress.)
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

User avatar
lulzfish
Posts: 1214
Joined: Tue Dec 16, 2008 8:17 am UTC

Re: Coding: Fleeting Thoughts

Postby lulzfish » Thu Oct 22, 2009 6:36 am UTC

After a few minutes with Irrlicht, I remembered why I left the last time: The transform system is confusing and I'm never sure if a bug is in the Blender exporter, the Irrlicht importer, or in my code.

So I'm going to stay with my own graphics library, where the transform system is easy to understand, and there's at least several bugs in each part of the program, but I'm familiar with them, so I can fix them easily.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Thu Oct 22, 2009 2:23 pm UTC

Argh. I just spent an hour trying to bugfix a simple x86 assembler program, only to remember that "DEC ESI" resets EFLAGS.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
'; DROP DATABASE;--
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy
Contact:

Re: Coding: Fleeting Thoughts

Postby '; DROP DATABASE;-- » Fri Oct 23, 2009 6:26 am UTC

I feel smug. I'm having to take a Java/intro to programming course for my diploma. Today while the teacher wrote a simple Fibonacci calculator on the whiteboard to demonstrate loops, I wrote my own on paper. In 12 lines* of MIPS assembly. :D

I don't feel like digging the paper out, but maybe tomorrow. The important part is I feel smug about it.

*Well, 13 if you count the NOP to fill the branch delay at the end. >_>

[edit] Not that anyone cares, but here it is:

Code: Select all

ADDIU $T0, $zero, 0001
ADDIU $T1, $zero, 0001
SW $T0, 0000($A0)
SW $T1, 0004($A0)
.loop: ADD $T2, $T1, $T0
SW $T2, 0008($A0)
OR $T0, $T1, $zero
OR $T1, $T2, $zero
ADDIU $A1, $A1, 0xFFFF
BNE $A1, $zero, .loop
ADDIU $A0, $A0, 0004
JR $RA
OR $A0, $T2, $zero
Inputs: $A0=pointer to array, $A1=# elements minus two. Fills array with Fibonacci numbers (32-bit integer).
How you'd output that is beyond the scope of this, as it depends on the host system.

[edit] If I change that last NOP in the branch delay, it also returns the last number it calculated in $A0 (instead of $T2 which is not standard behaviour). May as well. :-p

...and now it actually works >_>
Last edited by '; DROP DATABASE;-- on Sat Oct 24, 2009 9:22 pm UTC, edited 6 times in total.
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Fri Oct 23, 2009 1:36 pm UTC

The other day, my Java teacher was discussing applications of depth-first-search for pathfinding, which is the most hellishly inefficient way I could imagine solving that problem. It took all my effort to resist the urge to wave my real games coding experience at him and tell him how wrong he was. The only way I keep my sanity in that class is by doing half of my work in Jython. The only actual code he looks at is our main method, which he only looks at in order to run it.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
Xanthir
My HERO!!!
Posts: 5400
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Fri Oct 23, 2009 2:28 pm UTC

headprogrammingczar wrote:The other day, my Java teacher was discussing applications of depth-first-search for pathfinding, which is the most hellishly inefficient way I could imagine solving that problem. It took all my effort to resist the urge to wave my real games coding experience at him and tell him how wrong he was. The only way I keep my sanity in that class is by doing half of my work in Jython. The only actual code he looks at is our main method, which he only looks at in order to run it.

That... that doesn't even make *sense*. How would that *ever* be a good idea in *anyone's* mind?

Question: would random walk (with loop reduction) be more or less efficient than dfs? I suppose it depends on the graph.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

Xami
Posts: 74
Joined: Tue Sep 29, 2009 8:29 pm UTC

Re: Coding: Fleeting Thoughts

Postby Xami » Fri Oct 23, 2009 2:38 pm UTC

Was your teacher professing this as what you should do in that situation, or was this more of a - this is how it works type lecture?

User avatar
Xanthir
My HERO!!!
Posts: 5400
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Fri Oct 23, 2009 2:48 pm UTC

Either way, man, bad move on the prof's part. People *remember* these things. Someday someone's going to try and implement pathfinding with dfs because of some tickle in their brain, and it will be this prof's fault.

There's never an excuse to use bad examples in algorithms.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Coding: Fleeting Thoughts

Postby 0xBADFEED » Fri Oct 23, 2009 3:07 pm UTC

Xanthir wrote:Either way, man, bad move on the prof's part. People *remember* these things. Someday someone's going to try and implement pathfinding with dfs because of some tickle in their brain, and it will be this prof's fault.
There's never an excuse to use bad examples in algorithms.

I don't know. I think the context makes a great deal of difference. I mean if you're introducing path-finding or graph-searching, start with the simplest most brain-dead approach. Then work your way up to increasingly elegant, sophisticated methods. If someone doesn't understand DFS or BFS there's no way they're going to understand A* or more complex path-finding algorithms.

User avatar
Xanthir
My HERO!!!
Posts: 5400
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Fri Oct 23, 2009 6:19 pm UTC

Two responses:

1. BFS is a better pathfinder than DFS anyway, if we're talking about simple-but-stupid solutions.
2. Don't teach pathfinding at all if the class doesn't know enough to appreciate the beauty of A*. There are other things you can use to demonstrate DFS, like solving a peg-jumping game.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Coding: Fleeting Thoughts

Postby Random832 » Fri Oct 23, 2009 7:04 pm UTC

Isn't DFS unbounded for pathfinding? (i.e. keep walking in circles) Or are you also marking each space to make sure you don't visit it twice?

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Coding: Fleeting Thoughts

Postby 0xBADFEED » Fri Oct 23, 2009 8:01 pm UTC

Random832 wrote:Isn't DFS unbounded for pathfinding? (i.e. keep walking in circles) Or are you also marking each space to make sure you don't visit it twice?

Any correct DFS implementation will only visit a node once. It will not get caught in cycles.
Xanthir wrote:Two responses:
1. BFS is a better pathfinder than DFS anyway, if we're talking about simple-but-stupid solutions.
2. Don't teach pathfinding at all if the class doesn't know enough to appreciate the beauty of A*. There are other things you can use to demonstrate DFS, like solving a peg-jumping game.

I'm not debating whether or not DFS is a bad path-finding algorithm. It is. I just don't think headprogrammingczar gave us enough context to make any value judgments about the professor from it. It may have been a perfectly reasonable example. We don't know. I take headprogrammingczar's account, which seemed mostly framed to present his superiority over the professor, with a healthy dose of skepticism.

Also, it's a bad idea to judge your professors based on material they present in an introductory programming course. It's likely he/she knows that straight DFS is a bad path-finding approach. Unless he said something utterly ridiculous, like DFS is the most efficient path-finding algorithm there is, I would let it slide. Although it's also entirely possible he's an incompetent boob.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Fri Oct 23, 2009 9:41 pm UTC

Wow, this thread got busy. I was a bit vague when wording my other post, so I will clarify. He was using dfs to implement the filling algorithm in MS Paint, and at the end of the lecture, he said "this is also how modern games do pathfinding", rather pointedly at me (because I do coding on the Source engine), and segued that into a discussion of what algorithms are common in real programs. Normally, I would let that slide, since old programmers don't know much of anything about games unless they are in the industry, but his career history prior to teaching is 20 years in the Army band, followed by a few years in college and a year in IT.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Coding: Fleeting Thoughts

Postby 0xBADFEED » Fri Oct 23, 2009 10:09 pm UTC

headprogrammingczar wrote:Wow, this thread got busy. I was a bit vague when wording my other post, so I will clarify. He was using dfs to implement the filling algorithm in MS Paint, and at the end of the lecture, he said "this is also how modern games do pathfinding", rather pointedly at me (because I do coding on the Source engine), and segued that into a discussion of what algorithms are common in real programs. Normally, I would let that slide, since old programmers don't know much of anything about games unless they are in the industry, but his career history prior to teaching is 20 years in the Army band, followed by a few years in college and a year in IT.

Ah, OK. To his credit, I think a flood-fill algorithm is a perfectly acceptable example of DFS. It's not really great for implementing a flood-fill but I think it's fine for getting the point across. Also, it's easy to implement and about the right level for an intro programming course.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Mon Oct 26, 2009 8:09 pm UTC

Woo, datamining!

Code: Select all

*Main Text.XML.HXT.Arrow> print =<< runX ((arr length &&& arr head) .listA (isA ((=="Berengal").lastPostBy) . test_allFirstPageTopics))

[(3,Topic {topicTitle = "Lazy IO in Haskell", topicNr = 46780, forum = Forum {forumName = "Coding", forumNr = 11}, isSticky = False, topicOriginator = "phlip", topicCreatedDate = "Wed Oct 21, 2009 2:52 am UTC", lastPostBy = "Berengal", lastPostDate = "Wed Oct 21, 2009 4:45 pm UTC", numReplies = 3, numViews = 150})]


I wonder how much semantic information can be reliably extracted from the fora using nothing but html. I still have to work around the pagination, and start looking inside topics.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
lulzfish
Posts: 1214
Joined: Tue Dec 16, 2008 8:17 am UTC

Re: Coding: Fleeting Thoughts

Postby lulzfish » Mon Oct 26, 2009 8:31 pm UTC

Man, I remember back when data mining was considered bad, and was right up there with "spyware" and "identity theft".
Good times.

User avatar
Briareos
Posts: 1940
Joined: Thu Jul 12, 2007 12:40 pm UTC
Location: Town of the Big House

Re: Coding: Fleeting Thoughts

Postby Briareos » Tue Oct 27, 2009 8:53 am UTC

In one evening of panicked hacking I have sworn allegiance to gdb and valgrind.
Sandry wrote:Bless you, Briareos.

Blriaraisghaasghoasufdpt.
Oregonaut wrote:Briareos is my new bestest friend.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Tue Oct 27, 2009 11:29 am UTC

You know what I just realized as I skimmed over this page, first reading some GTK+ code in C, and then some assembly code? GTK+ code reads a lot like assembly in that you write a huge amount of code to get not a whole lot of stuff done.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Wed Oct 28, 2009 1:02 am UTC

<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

notallama
Posts: 236
Joined: Fri Jun 01, 2007 4:28 pm UTC

Re: Coding: Fleeting Thoughts

Postby notallama » Wed Oct 28, 2009 2:49 am UTC


i have been meaning to take a look at that for a while now.
i have far too many projects i'll never finish on the go already, though.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Thu Oct 29, 2009 10:44 pm UTC

I've been going through the documentation and holy shit scene graphs are powerful. Need an octree? Just make a Node with eight children. The only feature I found lacking was the refraction effect accompanying their dynamic wave generation. It splits the scene on a flat water plane, and doesn't update it to reflect the water height changes.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 14 guests