Coding: Fleeting Thoughts

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

Moderators: phlip, Moderators General, Prelates

User avatar
bridge
Posts: 195
Joined: Sun Feb 03, 2008 2:24 pm UTC
Location: Zurich < x < Rome

Re: Coding: Fleeting Thoughts

Postby bridge » Tue May 06, 2008 7:28 pm UTC

I'm sure about smalltalk
Excuse my Super Mario accent

btilly
Posts: 1877
Joined: Tue Nov 06, 2007 7:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby btilly » Tue May 06, 2008 8:11 pm UTC

'; DROP DATABASE;-- wrote:Are there any languages with self-modification support?

Yes, lots.

Smalltalk is mostly written in Smalltalk. Lisp macros are immensely powerful. There is a Perl module which lets you write your programs in Latin. Anything you can imagine, and quite a few you can't, are done by some language, somewhere.
Some of us exist to find out what can and can't be done.

Others exist to hold the beer.

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Coding: Fleeting Thoughts

Postby Rysto » Tue May 06, 2008 8:26 pm UTC

I was under the impression that Lisp macros allow you to change the semantics of the syntax, not modify the code itself.

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 » Tue May 06, 2008 8:37 pm UTC

Python also allows runtime modification easily:

Code: Select all

>>> import threading
>>> import time
>>> class Foo(threading.Thread):
   def __init__(self):
      threading.Thread.__init__(self)
      self.running = True
   def run(self):
      while self.running:
         print getString()
         time.sleep(4)

         
>>> f = Foo()
>>> getString = lambda:"Hello world!"
>>> f.start()
Hello world!
>>>
Hello world!
Hello world!
getString = lambda:"Goodbye cruel world!"
>>> Goodbye cruel world!
Goodbye cruel world!
f.running = False
>>>

Since it's interpreted dynamically, essentially every session starts blank and modifies its runtime libraries through code, adding new functions and classes as it goes along.
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 » Tue May 06, 2008 8:47 pm UTC

Berengal wrote:Since it's interpreted dynamically, essentially every session starts blank and modifies its runtime libraries through code, adding new functions and classes as it goes along.


As does perl, ruby, javascript and almost every scripted language :-P

Rysto wrote:I was under the impression that Lisp macros allow you to change the semantics of the syntax, not modify the code itself.

Lisp macro's can generate code for you. It can allow you to use a 'modified' semantic when writing your code, but fundamentally its just an extremely powerful and complicated preprocess.

a simple example:

Code: Select all

(defmacro triple (x)
    '(+ ~x ~x ~x))

(triple 4)
; evaluates to:
(+ 4 4 4)

; but you can pass it code, and it does a similar thing so say you did...
(triple (Foo 2))

; evaluates to

(+ (Foo 2) (Foo 2) (Foo 2))


It gives you the ability to extend the semantics in a way you want, but its really just a code generation too.
# drinks WAY to much espresso

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Tue May 06, 2008 9:10 pm UTC

Code generation isn't really self-modifying code though.

User avatar
cypher
Posts: 41
Joined: Mon May 05, 2008 9:22 pm UTC

Re: Coding: Fleeting Thoughts

Postby cypher » Tue May 06, 2008 9:19 pm UTC

LDJosh wrote:OK. Looks like this board needs a fleeting thoughts thread. - Hammer

While testing some session data handlers, I passed an unset variable to php with the date/time format set. instead of an error, php gives me the 'beginning' of time. so according to php, time began on:

1969 12 31 19:00:00

december 31st, 1969 at 7pm sharp huh?

well let’s see when it will end. Launch outlook, go to tasks. enter a task (like live forever). in the due date, put “forever”.

Seems like time will end on:

Tue 8/31/4500

neat stuff, huh?
This is what I did at work today.


this is an odd thing to point out, but there was an xkcd comic where a character claimed the universe was only 30 years old and anyone claiming to be over 30 is lying. I couldn't find it, but I'm still looking.

Anyhow, that would make the punchline much funnier, because the program claims the universe started in 1969, and 30 years later that would be 1999. It is possible that could have been a reference to that coding line.

g2g. peace.
find the limit as x approaches infinity of
___x___
(x2+1)1/2
using L'Hôpital's rule.

btilly
Posts: 1877
Joined: Tue Nov 06, 2007 7:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby btilly » Tue May 06, 2008 9:55 pm UTC

Rysto wrote:I was under the impression that Lisp macros allow you to change the semantics of the syntax, not modify the code itself.

There are two types of Lisp macros.

Reader macros allow you to rewrite code while it is still being read in. You could in principle use them to create any syntax in the world. In practice there are only a few reader macros that are ever used, like the one that translates 'foo into (QUOTE foo). The reason more aren't use is that reader macros do not play well with each other, and heavy use of reader macros would result in a language that no longer feels like Lisp.

Ordinary macros are different. They can rewrite code in any way you wish. They don't change the syntax, they just rearrange pieces of code. That "just" hides a world of power. Suppose you need a new control structure that isn't in the language? A macro will do it. The power of that statement is hard to communicate to anyone who hasn't ever seen code that does it. If you wish to appreciate Lisp macros, I highly recommend reading On Lisp. (If your budget will afford, I suggest buying the book. But it is up to you.)
Some of us exist to find out what can and can't be done.

Others exist to hold the beer.

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 » Tue May 06, 2008 10:01 pm UTC

Behold the power of self-modifying code:

Code: Select all

def getNext():
   global getNext
   i = 1
   s = "def getNext2():global getNext; i = %d; s = %s; s2 = %s; s = s %s; exec s; getNext = getNext2; return i"
   s2 = "% (i+1, repr(s), repr(s2), s2)"
   s = s % (i+1, repr(s), repr(s2), s2)
   exec s
   getNext = getNext2
   return i

>>> getNext()
1
>>> getNext()
2
>>> getNext()
3


Now, if only it were useful...
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.

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Coding: Fleeting Thoughts

Postby qbg » Wed May 07, 2008 12:47 am UTC

In Common Lisp, you have the compiler available at run time, and of course you have EVAL.

Macros, (compiled) closures, etc. gives you a lot of power, so self-modifying code usually isn't needed.

User avatar
wing
the /b/slayer
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Coding: Fleeting Thoughts

Postby wing » Wed May 07, 2008 1:00 am UTC

btilly wrote:There is a Perl module which lets you write your programs in Latin.

That sounds utterly useless.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.

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 » Wed May 07, 2008 1:18 am UTC

wing wrote:
btilly wrote:There is a Perl module which lets you write your programs in Latin.

That sounds utterly useless.

From a pragmatic standpoint, yes. It is however interesting in that latin is based on inflection, not position, so parsing is quite different.
For example, in english, "The man ate the sandwich" is quite different from "The sandwich ate the man", but in inflected languages they would be equal as long as the inflections didn't change.
An example of a statement that doesn't change meaning depending on position in english is "'It's hot today' said the man."/"The man said 'it's hot today.'"
Due to the many different inflections in latin, one can reorder the words in a sentence as much one likes without it changing meaning.
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.

btilly
Posts: 1877
Joined: Tue Nov 06, 2007 7:08 pm UTC

Re: Coding: Fleeting Thoughts

Postby btilly » Wed May 07, 2008 1:34 am UTC

wing wrote:
btilly wrote:There is a Perl module which lets you write your programs in Latin.

That sounds utterly useless.

I've heard of it being used in production.

Mind you it was used by a programmer who was extremely pissed off, and so he ported his code from Perl to Latin as an FU before he quit. But it did wind up in production.
Some of us exist to find out what can and can't be done.

Others exist to hold the beer.

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

Re: Coding: Fleeting Thoughts

Postby Xanthir » Fri May 09, 2008 6:43 pm UTC

rrwoods wrote:I'm not too familiar with it, but I think Lisp has pretty heavy self-modification support.

As others have said, Lisp doesn't have self-modification per se, at least not in the form that *that* code has where arbitrary instructions later on can change things. That's the devil.

Lisp macros are where the power is at. Lisp gives you the full power of the language at all times - write, compile, and execute time. Macros are functions that run at compile time, and return code. You can *also* call them at runtime, of course, but their power is in allowing you to provide entirely new syntax structures. This is mostly possible because Lisp has next to no typographical syntax - it's all just lists wrapped in parentheses, with the actual 'syntax', as it were, implicit in the definition of things. Frex, a C for loop has a magic syntax that nothing else can ever use, even if you have something that could benefit from a similar structure. On the other hand, the (very basic) analogue for "for" in lisp is dotimes, which is invoked as (dotimes (counter limit returnvar) --code here--). If you think that looks just like a list wrapped in parentheses, you'd be right. It's exactly like every other function and can be easily created and transformed by the standard list-manipulation functions built-in to Lisp.

Fun note: Dotimes is actually a macro! It transforms the code passed to it into a

Code: Select all

(do
    ((var init-val update-val)
    --repeat for more vars)
    ((end-test) return-val)
    --code here--)
statement, which is a lot more complex to code (and much more than you typically need when you're just iterating a variable from zero.

Extra fun note: Do is actually a macro! It transforms the code passed to it into a (tagbody) block of statements, which is *even more* complex to code (and way more than you pretty much ever need, since tagbody is lisp's name for goto). Macros can generate macros which can generate macros. This continues until the macros finally output ordinary functions or values, at which point they get compiled. It's actually possible to implement the entire language as a series of macros over a mere 7 base functions that form the core of lisp, though in practice this isn't done.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
tehmikey
Posts: 184
Joined: Mon Mar 17, 2008 4:32 pm UTC
Contact:

Re: Coding: Fleeting Thoughts

Postby tehmikey » Fri May 09, 2008 8:00 pm UTC

FT: I wish I would have implemented a random sort on small sets of data when I was first learning to program. Many highschool teachers and professors look at the output before the code. The VASTLY varying efficiencies would prove frustrating to all testers.

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 May 09, 2008 8:40 pm UTC

tehmikey wrote:FT: I wish I would have implemented a random sort on small sets of data when I was first learning to program. Many highschool teachers and professors look at the output before the code. The VASTLY varying efficiencies would prove frustrating to all testers.

Oh, indeed. If you're shuffling the whole list, not just swapping two items, between sorted checks, bogosort is O(n!) on average. 7! = 5040. 8! = 40320. 9! = 362880.
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
wing
the /b/slayer
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Coding: Fleeting Thoughts

Postby wing » Fri May 09, 2008 11:15 pm UTC

Berengal wrote:
tehmikey wrote:FT: I wish I would have implemented a random sort on small sets of data when I was first learning to program. Many highschool teachers and professors look at the output before the code. The VASTLY varying efficiencies would prove frustrating to all testers.

Oh, indeed. If you're shuffling the whole list, not just swapping two items, between sorted checks, bogosort is O(n!) on average. 7! = 5040. 8! = 40320. 9! = 362880.

But *QUANTUM* bogosort is O(1) - which is WAY superior to everything else.

[Quantum bogosort is bogosort whewre you randomize once, and then check all possible realities to see which one contains the sorted list, and discard the rest]
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Coding: Fleeting Thoughts

Postby Rysto » Fri May 09, 2008 11:19 pm UTC

Shouldn't it be O(n)? You have to check whether the list is sorted.

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

Re: Coding: Fleeting Thoughts

Postby Xanthir » Sat May 10, 2008 2:18 am UTC

wing wrote:
Berengal wrote:
tehmikey wrote:FT: I wish I would have implemented a random sort on small sets of data when I was first learning to program. Many highschool teachers and professors look at the output before the code. The VASTLY varying efficiencies would prove frustrating to all testers.

Oh, indeed. If you're shuffling the whole list, not just swapping two items, between sorted checks, bogosort is O(n!) on average. 7! = 5040. 8! = 40320. 9! = 362880.

But *QUANTUM* bogosort is O(1) - which is WAY superior to everything else.

[Quantum bogosort is bogosort whewre you randomize once, and then check all possible realities to see which one contains the sorted list, and discard the rest]

(I know it's a joke, but...) Quantum algorithms don't work like that. They *randomly* select a possible answer from all their combined states. If you've got 10! possibilities and only one's right, that's a pretty small chance of it returning correctly.

The secret is to do statistical tricks that manipulate the frequency space and cancel out as many of the wrong answers as possible. That way your correct answer is a lot more likely to come up. Rerun the algo a few times to get an acceptable bounded probability of being correct, and you're good.

This is why quantum computers aren't magic. Most problems aren't amenable to the sort of frequency-space manipulation of their answer space that is required, or at least, aren't amenable to that in a reasonable amount of time (taking longer to rearrange the space than it would take to just use a classical algorithm is clearly a losing situation).
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Sat May 10, 2008 10:19 pm UTC

A tutorial I've been reading wrote:DirectX only draws triangles that are facing the camera. DirectX defines that triangles facing the camera should be drawn clockwise relative to the camera. If you position the camera on the negative z-axis, the triangle will be defined counter-clockwise relative to the camera, and thus will not be drawn! One way to remove this problem is simply redefining the vertices clockwise (this time clockwise relative to our camera on the negative part of the Z axis)


This is one of those EUREKA! Moments for me, but assuming most graphics engines do this, it explains why when the camera gets stuck in an object it draws only strange parts of the object. It just makes so much sense I kinda went "duh, why didn't I think of that". :mrgreen: Woo learning how things work. :o

In any case learning DirectX is interesting, but I'm only playing around with it a tiny bit at the moment, I'll probably try doing the whole tutorial or something once finals week is over, fun fun. :D

User avatar
Dropzone
Posts: 405
Joined: Sun Dec 30, 2007 10:12 pm UTC
Location: North Lincs., UK

Re: Coding: Fleeting Thoughts

Postby Dropzone » Sun Jun 15, 2008 7:21 pm UTC

All hope abandon, ye who enter here. This has to be the most overcomplicated and underdocumented piece of Java API I've ever seen...

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;-- » Tue Jun 17, 2008 6:05 am UTC

libGD is so much easier to use in PHP than in C. :(
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

Talion
Posts: 3
Joined: Wed Jun 18, 2008 12:58 am UTC

Re: Coding: Fleeting Thoughts

Postby Talion » Wed Jun 18, 2008 2:45 am UTC

javascript mutator code:

Code: Select all

function f() {
   alert( 'sheep function says baaa' );
}
function mutate(x) {
  eval('x = '+
  (x+'')
   .replace(/sheep/g, 'zergling')
   .replace(/baaa/g, 'khkhkh')
   .replace(/alert/g, 'document.body.innerHTML = '));
  return x;
}
f = mutate(f);

f();

User avatar
3fj
Posts: 1715
Joined: Wed Jun 11, 2008 1:13 pm UTC
Location: Land of Whisky and Bagpipes (LOWAB)
Contact:

Re: Coding: Fleeting Thoughts

Postby 3fj » Wed Jun 18, 2008 7:03 pm UTC

Dropzone wrote:All hope abandon, ye who enter here. This has to be the most overcomplicated and underdocumented piece of Java API I've ever seen...


Had to look at this at 3am after missing a lecture and having a project to hand in.

I'm not ashamed to admit that i cried.
Everything's dead until it's alive. Man will exist, and then he will die. Just take the ride!

User avatar
sparkyb
Posts: 1091
Joined: Thu Sep 06, 2007 7:30 pm UTC
Location: Camberville proper!
Contact:

Re: Coding: Fleeting Thoughts

Postby sparkyb » Wed Jun 18, 2008 7:33 pm UTC

Dropzone wrote:All hope abandon, ye who enter here. This has to be the most overcomplicated and underdocumented piece of Java API I've ever seen...


Then apparently you've never tried to do anything significant with JMF (Java Media Framework).

User avatar
Marz
Posts: 156
Joined: Mon Dec 10, 2007 9:13 pm UTC
Location: UK
Contact:

Re: Coding: Fleeting Thoughts

Postby Marz » Mon Jun 23, 2008 5:02 pm UTC

Befunge is an esoteric language allowing self-modifying code.
All code exists in Fungespace, from which you may get, put, and interpret.
But it's more for fun than actual programming. It was interesting to write an Interpreter for, though.

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 Jun 23, 2008 11:47 pm UTC

Marz wrote:Befunge is an esoteric language allowing self-modifying code.
All code exists in Fungespace, from which you may get, put, and interpret.
But it's more for fun than actual programming. It was interesting to write an Interpreter for, though.

Now write a compiler.
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
The Hyphenator
Posts: 791
Joined: Mon Nov 19, 2007 2:16 am UTC
Location: The Shades, Ankh-Morpork

Re: Coding: Fleeting Thoughts

Postby The Hyphenator » Wed Jul 02, 2008 2:04 am UTC

Goddammit, I just spent an hour on a tic-tac-toe AI. It took me half that time to just get my shit together and realize my current approach wasn't working. Now I finally got really started, although it's not even close to being close to done yet. Why can I never do things right the first time?

*bangs head against wall*
The image link changes whenever I find a new cool website.
Spoiler:
Image

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 » Wed Jul 02, 2008 3:01 am UTC

Would you really need an AI though? Isn't that game small enough to brute-force a game-tree?

Of course, writing an AI can be fun too.
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
The Hyphenator
Posts: 791
Joined: Mon Nov 19, 2007 2:16 am UTC
Location: The Shades, Ankh-Morpork

Re: Coding: Fleeting Thoughts

Postby The Hyphenator » Mon Jul 07, 2008 3:20 pm UTC

Berengal wrote:Would you really need an AI though? Isn't that game small enough to brute-force a game-tree?

Of course, writing an AI can be fun too.

Well, I've never written either an AI or a game tree before (except for a really basic AI in one of my games), so I just thought an AI would be a cool thing to try. :oops:

*wikis game tree*

Since my AI is still having... problems, I'll probably do that instead.
The image link changes whenever I find a new cool website.
Spoiler:
Image

User avatar
Ptolom
Posts: 1559
Joined: Mon Mar 24, 2008 1:55 pm UTC
Location: The entropy pool
Contact:

Re: Coding: Fleeting Thoughts

Postby Ptolom » Fri Jul 11, 2008 8:01 pm UTC

why is it so goddamn hard to write a simple tile based game engine? It looked so simple, just draw the tiles on a grid and then feed back some data when they're walked on. Now I'm grappling with a program to read through huge text files full of cryptic lists of letters. Why is it never simple

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Sat Jul 12, 2008 2:00 am UTC

Ptolom wrote:why is it so goddamn hard to write a simple tile based game engine? It looked so simple, just draw the tiles on a grid and then feed back some data when they're walked on. Now I'm grappling with a program to read through huge text files full of cryptic lists of letters. Why is it never simple

Doesn't seem that hard. I wrote a simple tile based engine (I assume we're talking 2D?). In retrospect though, I didn't make it very modular, nor comment the code, but I had the aspiration to code a game as my first 'big' project.

I never did actually work on the 'game' part, just the engine, quite fun. Its filed under my "technically finished, but I never coded some things that would be useful to actually finish making a game out of it" folder. I even had a spiffy map editor. :mrgreen:

Maybe try breaking it into smaller pieces? Like, don't try to get all the features running at once, go for just the map tiles first (should be fairly easy to just draw the correct image at each position). Then work up I guess? :X

User avatar
The Hyphenator
Posts: 791
Joined: Mon Nov 19, 2007 2:16 am UTC
Location: The Shades, Ankh-Morpork

Re: Coding: Fleeting Thoughts

Postby The Hyphenator » Mon Jul 14, 2008 12:06 am UTC

It worked the first time?

It worked the first time?

So I was just working on a program with a function with lots of bitwise operators, pointers, etc, and I expected to see a huge list of complaints on compile, but it compiled fine. Then I thought it would definitely return a memory error on runtime.

But it didn't! It worked perfectly! :shock:

Middle-of-reply edit: I just tried it with different inputs, and it still worked. I feel so proud. :D

What I was trying to do, if you care:
Spoiler:
Make a new ultra-optimized Game of Life implementation. I saved each of the 16 combinations of four cells in an image, so it would only have to display one-fourth as many surfaces (each surface has four cells, instead of one). The display function takes an 2-d array of bytes containing the cell data, one bit per cell. For each byte, the upper and lower four bits are converted into clip rectangle coordinates in the image, then that part of the image is displayed in the right place.

NP will tell me some simple way to optimize it further that I missed. :)
The image link changes whenever I find a new cool website.
Spoiler:
Image

azredwing
Posts: 17
Joined: Thu May 08, 2008 11:44 pm UTC

Re: Coding: Fleeting Thoughts

Postby azredwing » Mon Jul 14, 2008 12:40 am UTC

Fleeting thought:

I know C, Perl, and assembly. Until now, my style convention has been that all_variables_should_be_underscored.

I am now teaching myself Java, and the Java naming convention is that allVariablesShouldHaveCapitalLettersAndNoUnderscores.

Since it's all style, does it really matter if I kept the style of using underscores to separate words, rather than use capital letters? And how much would that piss off other Java programmers who looked at my code if I did?

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Mon Jul 14, 2008 7:20 am UTC

It's not a big deal, but it's best to stay idiomatic. For example, my style when writing C# is different to when I write C++ - in C# I generally follow the Microsoft guidelines because that's generally what a lot of C# code is written in. I assume the same would be for Java: when in Rome, do as the Romans do.

User avatar
xulaus
Posts: 136
Joined: Thu Jul 03, 2008 11:09 am UTC

Re: Coding: Fleeting Thoughts

Postby xulaus » Tue Jul 15, 2008 4:29 pm UTC

The dev team for PHP has a KISS policy. heh.
Meaux_Pas wrote:I don't even know who the fuck this guy is

User avatar
Duck
Posts: 29
Joined: Wed Apr 11, 2007 1:53 pm UTC
Location: Somerset, UK
Contact:

Re: Coding: Fleeting Thoughts

Postby Duck » Wed Jul 16, 2008 11:17 am UTC

Ptolom wrote:why is it so goddamn hard to write a simple tile based game engine? It looked so simple, just draw the tiles on a grid and then feed back some data when they're walked on. Now I'm grappling with a program to read through huge text files full of cryptic lists of letters. Why is it never simple


What part are you having trouble with?
In my experience, writing and reading lists of letters and numbers to and from files is something that most languages tend to be fairly good at.

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? » Wed Jul 16, 2008 9:25 pm UTC

'; DROP DATABASE;-- wrote:Interesting/terrifying idea: self-modifying C. A statement that says "change this other statement to this". Something like:

Code: Select all

for(int i=0; i<5; i++)
{
   fooequalsone:
   foo = 1;
   if(i > bar) break;
   change fooequalsone foo = 0;
}



Sort of like static in C-like languages. Oh, what shenanigans that keyword can be up to.

Code: Select all

void foo() {
        for(static int i = 0; i < 5; i++) printf("%d", i);
}

int main() {
        for(;;) foo();
        return 0;
}


When run, produces

01234[nothing]

:-D
Last edited by You, sir, name? on Thu Jul 17, 2008 2:26 pm UTC, edited 1 time in total.
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 Jul 16, 2008 9:59 pm UTC

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

User avatar
The Hyphenator
Posts: 791
Joined: Mon Nov 19, 2007 2:16 am UTC
Location: The Shades, Ankh-Morpork

Re: Coding: Fleeting Thoughts

Postby The Hyphenator » Thu Jul 31, 2008 10:18 pm UTC

Oh my god. Python rules.

This is the thought that has been running through my head repeatedly since I coded my first Python program yesterday morning. It really is JUST SO EASY. I've only used it for two days, and I already think it might be my favorite language.
The image link changes whenever I find a new cool website.
Spoiler:
Image


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 9 guests