The "IT DOESN'T WORK!" thread

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

Moderators: phlip, Moderators General, Prelates

|Erasmus|
Branson
Posts: 2643
Joined: Tue Oct 30, 2007 7:53 am UTC
Location: Sydney, Australia
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby |Erasmus| » Thu Nov 08, 2007 9:49 am UTC

I was getting a major change finished off at work today (obviously we use a revision control system).

I set it up to run some performance tests, to see if I was getting a performance improvement over the baseline. I had already tested it extensively on my own machine.

Anyway, I boot the mac machine into single user mode, run my change, and it hangs. I then proceed to do alot of testing, and eventually work out that this only happens when running it in single user mode on macos... it runs fine on every other architecture we have. It also turns out that it's not even my change, but the baseline will not work under these conditions. Unfortunately, we don't actually build or test MacOS by default, so I was the first to notice that anything may be going wrong...

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: The "IT DOESN'T WORK!" thread

Postby evilbeanfiend » Fri Nov 09, 2007 4:44 pm UTC

gah just spent hours wondering why something wasn't working before realising that 2 strings that i thought were comparing equal weren't. one was 'string' the other was '"string"'
in ur beanz makin u eveel

User avatar
thebeanie
Posts: 56
Joined: Mon Jun 11, 2007 10:13 am UTC
Location: Australia
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby thebeanie » Sat Nov 10, 2007 5:56 pm UTC

This is evil. My very first pyGTK script and it refuses to work. Well, not quite.

Code: Select all

#!/usr/bin/env python
import gtk
import gtk.glade

class HelloWorld:
        def __init__(self):
                #Set glade file
                self.gladefile = "helloworld.glade"
                self.wTree = gtk.glade.XML(self.gladefile)
                #Get main window and connect destroy even with quit
                self.window = self.wTree.get_widget("window1")
                if (self.window):
                        self.window.connect("destroy", gtk.main_quit)
                dic = { "on_btnbutton1_clicked": self.click,
                             "on_window1_destroy": self.quit }
                self.wTree.signal_autoconnect(dic)
       
        def clicked(self, widget):
                        print "Booyah."

        def quit(self, widget):
                        gtk.main_quit()

if __name__ == "__main__":
        hwg = HelloWorld()
        gtk.main()

As you can see, I've linked a button signal(clicked) to the function clicked(). But the callback fails. When I click the button clicked() does not run. WHHHHY?

User avatar
wr3cktangle
Posts: 75
Joined: Tue Aug 01, 2006 5:03 pm UTC

Re: The "IT DOESN'T WORK!" thread

Postby wr3cktangle » Sat Nov 10, 2007 6:20 pm UTC

i just spent a while trying to figure out why
unsigned long long num = 317584931803;
was giving me the error: "integer constant is too large for ‘long’ type" on my linux box even though it worked on the unix machine i originally wrote it on
when
unsigned long long num = 0;
num--;
gave me 18446744073709551615, which is clearly larger than the number i wanted to assign to it,
long story short, i had do write it as:
unsigned long long num = 317584931803ULL;


thebeanie wrote:This is evil. My very first pyGTK script and it refuses to work. Well, not quite.
Spoiler:

Code: Select all

#!/usr/bin/env python
import gtk
import gtk.glade

class HelloWorld:
        def __init__(self):
                #Set glade file
                self.gladefile = "helloworld.glade"
                self.wTree = gtk.glade.XML(self.gladefile)
                #Get main window and connect destroy even with quit
                self.window = self.wTree.get_widget("window1")
                if (self.window):
                        self.window.connect("destroy", gtk.main_quit)
                dic = { "on_btnbutton1_clicked": self.click,
                             "on_window1_destroy": self.quit }
                self.wTree.signal_autoconnect(dic)
       
        def clicked(self, widget):
                        print "Booyah."

        def quit(self, widget):
                        gtk.main_quit()

if __name__ == "__main__":
        hwg = HelloWorld()
        gtk.main()
As you can see, I've linked a button signal(clicked) to the function clicked(). But the callback fails. When I click the button clicked() does not run. WHHHHY?


my guess, seeing as i don't know python, and therefor don't know pyGTK, is that it looks as though you have a clicked() (past tense) function, but you linked button1_clicked with a function click() (present tense), and therefor it's not properly linked as intended. i could be wrong, and chances are good i am, but i've got nothing to lose with an incorrect attempt to help
Maxim 33. When faced with the unusual, self-destruct.
My blog

PlayerOne
Posts: 14
Joined: Tue Jul 31, 2007 12:41 am UTC

Re: The "IT DOESN'T WORK!" thread

Postby PlayerOne » Sun Nov 11, 2007 1:05 pm UTC

I'm writing a scheduler for my preemptively multitasked Lego Mindstorms operating system. After a little bit of nasty debugging, the core assembler routine that does the saving and restoring of task state started working quite nicely. Then I start spawning tasks, to demonstrate the awesomeness of preemptive multitasking...

... And the whole system freezes hard when I start more than 3 tasks. 1, 2 or 3 tasks, works great. start a fourth task, the whole system comes crashing down in under a second after bootup. Reproducibly.

Given that I believe that the only three numbers in existence are zero, one, and lots, I was extremely, extremely confused. What kind of bug crashes when you go from lots of tasks to lots of tasks?

After two days of pulling my hair out, I eventually narrowed it down to something in new_task, the function that creates a task descriptor and stack, and populates it with initial register values:

Code: Select all

static mv_task_t *new_task(nx_closure_t func, U32 stack_size) {
  mv_task_t *t;
  nx_task_stack_t *s;

  NX_ASSERT_MSG((stack_size & 0x3) == 0, "Stack must be\n4-byte aligned");

  t = nx_calloc(1, sizeof(*t));
  t->stack_base = nx_calloc(1, stack_size);

  /* The current stack pointer for a new task is the top of the stack minus one
   * stack descriptor, which contains the initial register values for the task.
   */
  t->stack_current = t->stack_base + stack_size - sizeof(*s);

  s = (nx_task_stack_t*)t->stack_current;

  s->pc = (U32)func;
  /* Start in System mode. */
  s->cpsr = 0x1F;
  /* If the function is Thumb code, twiddle the CPU state accordingly. */
  if (s->pc & 0x1) {
    s->pc &= ~1;
    s->cpsr |= 0x20;
  }

  return t;
}


More specifically, the following line:

Code: Select all

  t->stack_current = t->stack_base + stack_size - sizeof(*s);


Looks innocent. But t->stack_current is a pointer-to-4-byte-integer. And that's how pointer arithmetic means that when I allocated a 512 byte stack, the initial stack pointer was set somewhere 1.5k beyond the actual top of the stack. Epic fail.

Code: Select all

  t->stack_current = t->stack_base + ((stack_size - sizeof(*s)) >> 2);


8 character diff. Now what truly puzzles me is that it somehow managed to work properly up to 3 tasks, despite having me stepping all over memory allocator structures and kernel memory.

Pointer arithmetic, why dost thou hate me?

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

Re: The "IT DOESN'T WORK!" thread

Postby EvanED » Sun Nov 11, 2007 1:17 pm UTC

PlayerOne wrote:

Code: Select all

  t->stack_current = t->stack_base + ((stack_size - sizeof(*s)) >> 2);


8 character diff. Now what truly puzzles me is that it somehow managed to work properly up to 3 tasks, despite having me stepping all over memory allocator structures and kernel memory.

Pointer arithmetic, why dost thou hate me?

May I make a recommendation?

Code: Select all

  t->stack_current = t->stack_base + (stack_size - sizeof(*s)) / sizeof(*t->stack_base);


That way:
1) It's clearer what it's doing. (I had to think about why you were dividing by 4 for a second. And while we're on it, I also don't think people should use >> for division by a power of two. Again, it's less clear, and compilers have only been smart enough to do that substitution for you for speed for a decade and a half.) [EDIT: the second half of this comment assumes that there isn't something "weird" with the platform. I tend to think from a PC-centric viewpoint, and not everything carries over to embedded stuff.]

2) If you change the type of t->stack_base, recompile the code on a system with something other than 32-bit ints, etc., it will not re-break.

PlayerOne
Posts: 14
Joined: Tue Jul 31, 2007 12:41 am UTC

Re: The "IT DOESN'T WORK!" thread

Postby PlayerOne » Sun Nov 11, 2007 1:45 pm UTC

EvanED wrote:May I make a recommendation?

Code: Select all

  t->stack_current = t->stack_base + (stack_size - sizeof(*s)) / sizeof(*t->stack_base);


That way:
1) It's clearer what it's doing. (I had to think about why you were dividing by 4 for a second. And while we're on it, I also don't think people should use >> for division by a power of two. Again, it's less clear, and compilers have only been smart enough to do that substitution for you for speed for a decade and a half.)

I don't find your formulation any clearer, to be honest. But point taken regarding the division. I actually used a bitshift because I found the problem by staring at a disassembly of the function, and in the ARM instruction set, t->stack_base + stack_size (with the incorrect arithmetic) compiles to:

Code: Select all

  add r1, r0, r2, lsl #2

So I merely applied the reverse shift to see if the kernel actually booted properly. But a division would be cleaner.

2) If you change the type of t->stack_base, recompile the code on a system with something other than 32-bit ints, etc., it will not re-break.

Recompiling on a different platform will very likely not happen, since our project targets a single platform, the lego mindstorms NXT brick. That said, point also taken: if I don't make it automagic, it will come back and kick me when I'll have forgotten all about it.

Thanks for the code review!

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby thoughtfully » Mon Nov 12, 2007 8:32 pm UTC

thebeanie wrote:This is evil. My very first pyGTK script and it refuses to work. Well, not quite.
Spoiler:

Code: Select all

#!/usr/bin/env python
import gtk
import gtk.glade

class HelloWorld:
        def __init__(self):
                #Set glade file
                self.gladefile = "helloworld.glade"
                self.wTree = gtk.glade.XML(self.gladefile)
                #Get main window and connect destroy even with quit
                self.window = self.wTree.get_widget("window1")
                if (self.window):
                        self.window.connect("destroy", gtk.main_quit)
                dic = { "on_btnbutton1_clicked": self.click,
                             "on_window1_destroy": self.quit }
                self.wTree.signal_autoconnect(dic)
       
        def clicked(self, widget):
                        print "Booyah."

        def quit(self, widget):
                        gtk.main_quit()

if __name__ == "__main__":
        hwg = HelloWorld()
        gtk.main()

As you can see, I've linked a button signal(clicked) to the function clicked(). But the callback fails. When I click the button clicked() does not run. WHHHHY?



Hard to troubleshoot without the glade file. One pitfall to watch out for is that get_widget fails silently if the widget is not present/mistyped/etc. It returns None. If this lookup fails, the signal is not connected, and there is no feedback. It might be as simple as case sensitivity.

You also have to set up the signals explicitly in glade if you want the signal_autoconnect method to work. This also will not tell you much if the signals aren't actually defined. Sorry if you have these covered, but again, hard to verify without the glade file.

The usual troubleshooting advice applies. Verify the arguments and results of every function call, line of code, etc.

Linux Journal has a few articles on pyGTK and Glade. google is your friend.

PM me if you need more pyGTK help. I have developed several a few largish applications and can even provide some helper classes that take some of the hazards out of using glade.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

HappySmileMan
Posts: 52
Joined: Fri Nov 09, 2007 11:46 pm UTC

Re: The "IT DOESN'T WORK!" thread

Postby HappySmileMan » Mon Nov 12, 2007 11:55 pm UTC

I need to check whether a number goes into a 64-bit number evenly... On a 32-bit machine. I'm trying

Code: Select all

   uint64_t num = 317584931803LLU;
   uint64_t i = 0, result = 0;
   for (i=0; i<num; ++i)
   {
      if (!(num%i))
      {


And it gets a SIGFPE (Floating point exception) at that line(if (!(num%i))), never getting any further. How am I supposed to do this? I'm on Linux, and don't mind if it's portable or not, it's only for my own use (project euler #3), I'd prefer to get the right way of doing it in C++ than giving up and doing it in Python, but may end up doing it in Python if I can't get it.

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

Re: The "IT DOESN'T WORK!" thread

Postby Rysto » Tue Nov 13, 2007 2:43 am UTC

You're dividing by 0 in the first iteration of the loop.

HappySmileMan
Posts: 52
Joined: Fri Nov 09, 2007 11:46 pm UTC

Re: The "IT DOESN'T WORK!" thread

Postby HappySmileMan » Tue Nov 13, 2007 5:53 pm UTC

Rysto wrote:You're dividing by 0 in the first iteration of the loop.


It's always something strupid :P

Vempele
Posts: 69
Joined: Wed Nov 14, 2007 8:05 am UTC

Re: The "IT DOESN'T WORK!" thread

Postby Vempele » Wed Nov 14, 2007 8:19 am UTC

Code: Select all

                while ((bridgePosition != 5) || (bridgePosition != -5))


mabufo, you've got the same problem Berengal had just a few posts above yours. :roll:
const int ALMOST_FIFTY = 80;

User avatar
OfficiallyHaphazard
Age=postcount/60
Posts: 209
Joined: Tue Aug 28, 2007 2:56 pm UTC

Re: The "IT DOESN'T WORK!" thread

Postby OfficiallyHaphazard » Sun Nov 18, 2007 6:39 am UTC

Oh me yarm C drives me crazy sometimes (i.e. not having eclipse as a happy editor)

5 days stuck on the fact that I was appending newsArticle to my vector instead of newArticle

one measly "s"

damn thats annoying >.>
"Who are you, how did you get in my house?" - Donald Knuth

hic erro
Posts: 7
Joined: Sat Nov 17, 2007 5:51 pm UTC
Location: Astoria, NY

Re: The "IT DOESN'T WORK!" thread

Postby hic erro » Sun Nov 18, 2007 6:39 pm UTC

The craziest bug I ever (successfully) debugged involved #pragma pack. A header file declared a class:

Code: Select all

#pragma pack(4)
struct Foo {
  // ...
};
#pragma pack(0)


Now, there are two important things about this:
1. #pragma pack(0) does not 'turn off' packing. #pragma pack() does.
2. This header file was included in some compilation units but not in others.

The result of this was that a second class, minding its own business, was packed by the #pragma pack(0). In some compilation units. But not others. The class had different layouts in different compilation units.

This led to apparent memory corruption which was confused me completely: in instances of the inconsistently-packed class, a member would be set in one function, and set correctly, and everything would be fine, and then when the function returned, it would be magically corrupted!

Unfortunately, this bug happened when switching from 32 to 64 bits, months after the #pragma pack(0) was added, so the entire code-base was suspect.

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

Re: The "IT DOESN'T WORK!" thread

Postby Rysto » Sun Nov 18, 2007 10:31 pm UTC

And this is why #pragma was such a stupid idea.

Embryo
Posts: 31
Joined: Thu Oct 18, 2007 2:15 am UTC
Location: SF Bay Area

Re: The "IT DOESN'T WORK!" thread

Postby Embryo » Fri Nov 23, 2007 12:00 am UTC

Ok, here's my perplexing code issue. I'm trying to rewrite a chess program to do something, because I think it'd be cool, but it's kicking my ass.

I want to make it so that you can only see what your pieces see. Sounds simple, right? Well.

Here's the code for redrawing the board, as near as I could figure it out:


Spoiler:

Code: Select all

    public void redraw() {
        VisualFigure figure;
        int rank = 0, file = 0;
        List list = new Vector();
        list = virtualBoard.getAllVisible();       
        restoreBackground();
        for (int t = 1; t < allLists.length; t++)
            allLists[t].rewind();
        synchronized (virtualBoard) {
            for (rank = 0; rank < 8; rank++) {
                for (file = 0; file < 8; file++) {
                    int type = virtualBoard.field[(rank << 3) + file];
                    if (type != VirtualBoard.EMPTY_FIELD  &&  !list.contains((rank << 3) + file) ) {
                       figure = allLists[type].getFigure();
                        boardPane.add(figure, new Integer(2), 0);
                        figure.setField(rank, file);
                    }
                }
            }
            for (int t = 1; t < allLists.length; t++)
                allLists[t].hideRest();
        }



And here's getAllVisible, which I wrote.

Spoiler:

Code: Select all

    public List getAllVisible() {
       List list = new Vector();
       for (int n = 0; n < 64; n++) {
            if (isWhiteFigure(field[n])) {
               for (int m = 0; m < 64; m++) {
                  if (isPossibleMove(n, m) && !list.contains(m))
                     list.add(m);
             }
               if (!list.contains(n))
                        list.add(n);
          }
       }
       return list;
    }



I'm wracking my brain to figure this out. The code is totally uncommented and I can't figure out a lot of what he's doing (for instance, it took me about an hour to figure out that the 64 number was the position in the board as defined by (rank >> 3) + file). Treating his functions as opaque black boxes, this should work, but I'm absolutely certain I'm misusing List somehow. I wanted to use Set, but I can't figure out how to use that just from the Java API either!

This is really getting to be too much of a hassle (using someone else's code) and I'm on the verge of throwing this codebase out and looking for another one, or writing my own, but that'd be a lot of effort and I'm lazy. *grins*


What's happening right now is that it compiles, but everything is visible; all the black pieces and all the white pieces. What -should- be visible is only the legal moves of the white pieces and the white pieces themselves. Once I got this working, I was going to add one in front of all white pawns if there's a black piece in the way, and ta-da! fog of war chess.

Also, I generally don't use this bracket/indenting style, so I might have messed something up as well there.

Help?

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: The "IT DOESN'T WORK!" thread

Postby Yakk » Fri Nov 23, 2007 12:29 am UTC

hic erro wrote:The craziest bug I ever (successfully) debugged involved #pragma pack. A header file declared a class:

Code: Select all

#pragma pack(4)
struct Foo {
  // ...
};
#pragma pack(0)


Now, there are two important things about this:
1. #pragma pack(0) does not 'turn off' packing. #pragma pack() does.
2. This header file was included in some compilation units but not in others.

The result of this was that a second class, minding its own business, was packed by the #pragma pack(0). In some compilation units. But not others. The class had different layouts in different compilation units.

This led to apparent memory corruption which was confused me completely: in instances of the inconsistently-packed class, a member would be set in one function, and set correctly, and everything would be fine, and then when the function returned, it would be magically corrupted!

Unfortunately, this bug happened when switching from 32 to 64 bits, months after the #pragma pack(0) was added, so the entire code-base was suspect.


The right way to do this:
#pragma pack(push:4)
#pragma pack(pop)
or the local equivalent. Your trick breaks any global #pack changes done.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

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: The "IT DOESN'T WORK!" thread

Postby '; DROP DATABASE;-- » Fri Nov 23, 2007 12:50 am UTC

PlayerOne wrote:8 character diff. Now what truly puzzles me is that it somehow managed to work properly up to 3 tasks, despite having me stepping all over memory allocator structures and kernel memory.

Pointer arithmetic, why dost thou hate me?
Memory corruption always seems to have such bizarre symptoms. I find fopen() or fclose() will often crash. In one case, I did this:
char foo[10];
sprintf(foo, "%u", GetTickCount());
Forgetting that GetTickCount() could actually return a 10-digit number, so after the machine was up for about 11 days (1 billion msec), it would corrupt the very next byte after this array. Somehow this caused fopen() to crash in a completely unrelated area long after this happened. Naturally, the uptime was well below 11 days when I wrote this, so it didn't start breaking until some time later.

Now, what's really fun is learning the reason your program doesn't work is because your CPU actually has some very strange, rarely-occurring defect. >_< Eventually it got worse and the machine wouldn't even POST anymore, when I replaced it, the program worked fine ever since. Other things occasionally acted funny too, but never anything severe enough to make me suspect a hardware problem.
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

Embryo
Posts: 31
Joined: Thu Oct 18, 2007 2:15 am UTC
Location: SF Bay Area

Re: The "IT DOESN'T WORK!" thread

Postby Embryo » Fri Nov 23, 2007 2:02 am UTC

Rawr, I figured out my problem!

Or rather, my two problems. For some reason, I had to typecast as an Integer, and I misused a !.

Java is weird. Why would I have to typecast as an int something that already is an int? :( Makes the head hurt.

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: The "IT DOESN'T WORK!" thread

Postby '; DROP DATABASE;-- » Tue Nov 27, 2007 2:49 am UTC

So is there no way, short of dumping each individual window and blending them manually, to take a screenshot on Windows that includes translucent windows? I've tried getting a handle to the entire display and dumping that, and I get a shot with all the translucent windows gone, as if they were invisible. I've tried using EnumDisplayMonitors() to get a handle to each individual screen and dumping that, and I get the same result. (Also, AAAARRRRGGGHHHH at that process. It's such a twisted, convoluted mess to get working - it's still partially broken - and if you do something wrong, good luck figuring it out, because GetLastError() will return zero or you'll get a completely blank image. :x)

Pressing Print Screen and pasting into your favourite image program works fine, except on my machine, that doesn't work at all anymore. Claims to be out of memory. (Which isn't surprising, given a 32-bit dump of the entire display area is ~12MB, but it worked before. <_<) How is it getting this shot?

I've looked for existing programs, but only even managed to find one that wasn't expensive (pay for this? ha!), spyware-ridden, or both, and it doesn't even support multiple monitors let alone translucent windows. If I have to actually capture each window individually and blend them myself, I think I may just resort to taking a photo of the monitors instead. :roll:
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

User avatar
mabufo
Posts: 105
Joined: Sun Sep 09, 2007 11:17 pm UTC

Re: The "IT DOESN'T WORK!" thread

Postby mabufo » Tue Nov 27, 2007 4:09 pm UTC

I'm trying to count the number of vowels in a word... but I'm getting a string index out of range error as a result of my code. I'm having a hard time spotting the problem, could someone give it a look? The problem lies where I check for 'y' being a vowel:
Spoiler:

Code: Select all

/**
    * Returns false if the letter is a vowel, and true if it isn't
    * @param letter of type char
    * @return
    */
   public static boolean isConsonant(char letter){
      if(letter == 'a'){
         return false;}
      else if(letter == 'e'){
         return false;}
      else if(letter == 'i'){
         return false;}
      else if(letter == 'o'){
         return false;}
      else if(letter == 'u'){
         return false;}
      
      //returns true if letter is not a normal vowel
      return true;
      }

   /**
    * Returns true or false on the basis of a word being a vowel
    * @param word of type string
    * @return T or F
    */
   public static int vowelCount(String word){
      int vowels = 0;
      int n = 0;
      while (n < (word.length())){
         if (word.charAt(n) == 'a'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'e'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'i'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'o'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'u'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'y'){
            //if y is at the beginning... increment counter
            if(n == 0){
               n++;
            }
            //increments the vowel counter if y is at the end of a word
            else if(n == word.length()){
               vowels++;
               n++;
            }
            else{
               //if y is surrounded by consonants, increment vowel count
               if((isConsonant(word.charAt(n-1)) == true) && (isConsonant(word.charAt(n+1)) == true)){
                  vowels++;
               };
            n++;
            }
         }
         
         else{
            n++;};
         }   
      return vowels;         
      }

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

Re: The "IT DOESN'T WORK!" thread

Postby Rysto » Tue Nov 27, 2007 4:50 pm UTC

The problem is here:

if((isConsonant(word.charAt(n-1)) == true) && (isConsonant(word.charAt(n+1)) == true)){


If the word begins or ends with a 'y', one of the calls to charAt will be out of bounds.

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: The "IT DOESN'T WORK!" thread

Postby Berengal » Tue Nov 27, 2007 4:57 pm UTC

Also, else if(n == word.length()) will never fire, because the condition for the while loop is that n < word.length()
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
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby thoughtfully » Tue Nov 27, 2007 5:09 pm UTC

mabufo wrote:I'm trying to count the number of vowels in a word... but I'm getting a string index out of range error as a result of my code. I'm having a hard time spotting the problem, could someone give it a look? The problem lies where I check for 'y' being a vowel:
Spoiler:

Code: Select all

/**
    * Returns false if the letter is a vowel, and true if it isn't
    * @param letter of type char
    * @return
    */
   public static boolean isConsonant(char letter){
      if(letter == 'a'){
         return false;}
      else if(letter == 'e'){
         return false;}
      else if(letter == 'i'){
         return false;}
      else if(letter == 'o'){
         return false;}
      else if(letter == 'u'){
         return false;}
      
      //returns true if letter is not a normal vowel
      return true;
      }

   /**
    * Returns true or false on the basis of a word being a vowel
    * @param word of type string
    * @return T or F
    */
   public static int vowelCount(String word){
      int vowels = 0;
      int n = 0;
      while (n < (word.length())){
         if (word.charAt(n) == 'a'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'e'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'i'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'o'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'u'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'y'){
            //if y is at the beginning... increment counter
            if(n == 0){
               n++;
            }
            //increments the vowel counter if y is at the end of a word
            else if(n == word.length()){
               vowels++;
               n++;
            }
            else{
               //if y is surrounded by consonants, increment vowel count
               if((isConsonant(word.charAt(n-1)) == true) && (isConsonant(word.charAt(n+1)) == true)){
                  vowels++;
               };
            n++;
            }
         }
         
         else{
            n++;};
         }   
      return vowels;         
      }


Lordy, that's a lot of code. You can hide a lot of bugs in that beast.
What's worng with this (besides that it is a candidate for an obfuscated code contest!)

Code: Select all

int countVowels(char *u)
{
   int n=0;

   char *p, *q, s="aeiouy";

   for (p=u; *p; p++) for( q=s; *q; q++ ) if (*p == *q ) n++;

   return n;
}


Less is more, dontcha know.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

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

Re: The "IT DOESN'T WORK!" thread

Postby EvanED » Tue Nov 27, 2007 5:13 pm UTC

thoughtfully wrote:What's worng with this (besides that it is a candidate for an obfuscated code contest!)

You don't handle 'y' correctly.

(Where 'correctly' is defined as 'the way the original programmer intended')

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby thoughtfully » Tue Nov 27, 2007 6:02 pm UTC

EvanED wrote:
thoughtfully wrote:What's worng with this (besides that it is a candidate for an obfuscated code contest!)

You don't handle 'y' correctly.

(Where 'correctly' is defined as 'the way the original programmer intended')


Well, that and it could encourage bad habits in novice programmers. Mmmm, pointers!

Sorry, I was commenting more on style than on addressing bugs. It's like that sig I saw here or on slashdot:
anonymous sig wrote:Light a man a fire, you'll keep him warm for a day. Light a man on fire, and you'll keep him warm the rest of his life!


There only needs to be a single n++ in the while loop. Having one for each condition makes the code hard to understand and invites bugs later. You have two consonant checkers. Why not use your isConsonant function in the main loop? Also, comments like "n++; // increment counter" make us cringe. It's like line noise.

It would also be clearer and less error prone to handle y's special case seperately from the rest of the vowels. Unless two scans of the string are really very expensive, which isn't likely.

something like this

Code: Select all

   public static int vowelCount(String word){
      int vowels = 0;
      int n = 0;
      while (n < (word.length())){
         if (isConsonant(word.charAt(n)) == false){
            vowels++;
         }
         n++;
      }

      // increment vowels if y is at the end of a word or surrounded by consonants
      n = 1
      while (n < (word.length()-1)){
        if(word.charAt(n)) == 'y') {
            if((isConsonant(word.charAt(n-1)) == true) && (isConsonant(word.charAt(n+1)) == true)){
               vowels++;
            }
         }
         n++;
      }

      if (word.charAt(n) == 'y'){
         vowels++;
      }

      return vowels;
   }


Feeling the Burn yet?

EDIT: The first pass was a little dain-bramaged. Fix'd.

EDIT The Tooth:
phlip wrote:(BTW: thoughtfully: your code increments vowels if isConsonant returns true... I think that's a little backwards)


Thanks, fix'd
Last edited by thoughtfully on Tue Nov 27, 2007 10:55 pm UTC, edited 3 times in total.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

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

Re: The "IT DOESN'T WORK!" thread

Postby Rysto » Tue Nov 27, 2007 6:29 pm UTC

I don't think that doing it in two passes is cleaner. Do it in one pass using an "isVowel" function and handle the 'y' case specially.

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

Re: The "IT DOESN'T WORK!" thread

Postby Rysto » Tue Nov 27, 2007 6:30 pm UTC

Rysto wrote:The problem is here:

if((isConsonant(word.charAt(n-1)) == true) && (isConsonant(word.charAt(n+1)) == true)){


If the word begins or ends with a 'y', one of the calls to charAt will be out of bounds.

Scratch this, you handle both cases specially.

Hm, I'm not sure, then.

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby thoughtfully » Tue Nov 27, 2007 6:49 pm UTC

Well, you could do it in one pass, but you need to check the index

Code: Select all

   public static int vowelCount(String word){
      int vowels = 0;
      int n = 0;
      while (n < (word.length())){
         if (isConsonant(word.charAt(n)) == false){
            vowels++;
         }

         // increment vowels if y is at the end of a word or surrounded by consonants
         if (word.charAt(n) == 'y'){
            if (0<n && n<word.length()-1){
               if((isConsonant(word.charAt(n-1)) == true) && (isConsonant(word.charAt(n+1)) == true)){
                  vowels++;
               }
            }
            else {
               if (n==word.length()-1){
                  vowels++
               }
            }
         }
         n++;
      }
      return vowels;

Debatable, maybe, but I like mine better.
Last edited by thoughtfully on Tue Nov 27, 2007 10:56 pm UTC, edited 1 time in total.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

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: The "IT DOESN'T WORK!" thread

Postby Berengal » Tue Nov 27, 2007 9:26 pm UTC

How about regexes?
([aeiou]|[^aeiou]y[^aeiou]?)
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
phlip
Restorer of Worlds
Posts: 7573
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby phlip » Tue Nov 27, 2007 9:47 pm UTC

How about:

Code: Select all

public static int vowelCount(String word)
{
   int vowels = 0;
   bool previousConsonant = false;
   int wordlen = word.length();
   for (int n = 0; n < wordlen; n++)
   {
      if (word.charAt(n) == 'y')
      {
         // increment vowels if y is at the end of a word or surrounded by consonants
         if (previousConsonant && (n >= wordlen-1 || isConsonant(word.charAt(n+1))))
            vowels++;
         previousConsonant = true; // Makes it consistent with previous versions... may or may not be what you're after
      }
      else if (!isConsonant(word.charAt(n)))
      {
         previousConsonant = false;
         vowels++;
      }
      else
      {
         previousConsonant = true;
      }
   }
   return vowels;
}

The "previousConsonant = true" line inside the 'y' block can, of course, be changed to false, or even true or false depending on whether the 'y' was considered to be a vowel or not... it all depends on how you want it to treat double y's...
The other question is how you want it to treat the string "y"... the comment suggests it should return 1 (as it ends in a 'y') but this code, and all the other code for it, will return 0, as it's not preceded by a consonant.

Note that the short-circuit or means that word.charAt(n+1) won't get called at all if n is too big... so no bug there.

(BTW: thoughtfully: your code increments vowels if isConsonant returns true... I think that's a little backwards)

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
mabufo
Posts: 105
Joined: Sun Sep 09, 2007 11:17 pm UTC

Re: The "IT DOESN'T WORK!" thread

Postby mabufo » Tue Nov 27, 2007 10:35 pm UTC

The assignment has me going through the entire play of Hamlet to count words, vowels, and to display palindromes. That's like 32000 words. That's a lot of vowels, so I suppose speed is a bit of a factor. I am, however, trying to get this to work on a smaller scale. I'll run back and use some suggestions that I saw here, because I have a good idea of where i went wrong and what have you. I'll be sure and post back with a solution just in case anyone was interested.

Thank you everyone.

EDIT: also, the java doc on my second method was not correct. so ignore that I guess.

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby thoughtfully » Tue Nov 27, 2007 11:13 pm UTC

@phlip thanks for the tip on my code, I stopped checking when I switched to C++, for reasons which I'll leave to your imaginations :)

However.. your code makes the same out of bounds error as the OP's, unless you can rely on the n+1 not getting evaluated if the other half of that "||" isn't evaluated, (and the ">=" should be a "<="). I don't recall if this is in the standard or not, I think it probably is, but its a subtle trick to pull without comment :)

@mabufo: If this was an O(n2) algorithm, you might have some speed concerns, but for any normal desktop less than ten or fifteen years old a 32k input with any of these is going to whiz by, especially since you should only need to run it a few times.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

User avatar
phlip
Restorer of Worlds
Posts: 7573
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: The "IT DOESN'T WORK!" thread

Postby phlip » Tue Nov 27, 2007 11:45 pm UTC

thoughtfully wrote:However.. your code makes the same out of bounds error as the OP's, unless you can rely on the n+1 not getting evaluated if the other half of that "||" isn't evaluated, (and the ">=" should be a "<="). I don't recall if this is in the standard or not, I think it probably is, but its a subtle trick to pull without comment :)

No, I'm pretty sure it should be >=... and I did mention the short-circuit or in my comment at the bottom... just because it's not in a /**/ in the code doesn't make it any less of a comment ;)

Also: short-circuit ands and ors are a standard language feature of C, C++, Java, perl... I think the only language I've used that had ands/ors that didn't short-circuit is QBASIC/VB, which only had bitwise and/or, no logical and/or. Short-circuit logical operators are just one of those idioms you have to learn... at least, learn enough to understand them when someone else uses them.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

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

Re: The "IT DOESN'T WORK!" thread

Postby EvanED » Tue Nov 27, 2007 11:51 pm UTC

phlip wrote:Also: short-circuit ands and ors are a standard language feature of C, C++, Java, perl... I think the only language I've used that had ands/ors that didn't short-circuit is QBASIC/VB, which only had bitwise and/or, no logical and/or. Short-circuit logical operators are just one of those idioms you have to learn... at least, learn enough to understand them when someone else uses them.

Agreed. Short-circuiting behavior is rarely, in-and-of itself, comment-worthy. It's more common to see && short-circuited (e.g. "p && p->next"), but it really shouldn't take more than a second or two to figure out what's going on.

User avatar
mabufo
Posts: 105
Joined: Sun Sep 09, 2007 11:17 pm UTC

Re: The "IT DOESN'T WORK!" thread

Postby mabufo » Wed Nov 28, 2007 4:29 pm UTC

I've fixed the little problem that I was having. If you;re interested here is the finished code... and as far as I know it's working as it should:

Words Class:
Spoiler:

Code: Select all

/**
 * Series of methods to do work on each word in our text file
 *
 * @author Matt Young
 *
 */
public class Words {
   
   /**
    * method uses the stringReplace method to replace instances of
    * certain characters with whitespace
    *
    * @param word
    * @return modified word without punctuation and in lower-case
    */
   public static String wordCleaner(String word){
      //how it works:
      //if character code IN THE LAST INDEX is out of
      //the 97-122 range, split the string...
      
      
      // makes our word lower-case
      word = word.toLowerCase();
      
      //picks out punctuation in last character of string
      //if the last character is a letter, return the word
      char letter = word.charAt(word.length()-1);
      if (((int) letter >= 97) && ((int) letter <= 122)){
         return word;
      }
      //if the last character is not a letter
      //return everything before that character
      else{
         word = word.substring(0, (word.length()-1));
         return word;
      }
   }
   
   /**
    * Checks to see if a word is a palindrome
    * compares the first character to the last, 2nd to 2nd last... ect...
    * @param word
    * @return true or false
    */
   public static boolean isPalindrome(String word){
      int wordLength = word.length() - 1;
      int start = 0;
      
      while(start < wordLength){         
         //if the first and last letter don't match - forget it
         if (word.charAt(start) != word.charAt(wordLength)){
            return false;
         };
         //if they do, continue to make sure the next few do as well
         start++;
         wordLength--;
      }
      //return true after while condition is met
      return true;
         
      }
   
   /**
    * Returns false if the letter is a vowel, and true if it isn't
    * @param letter of type char
    * @return true or false
    */
   public static boolean isConsonant(char letter){
      if(letter == 'a'){
         return false;}
      else if(letter == 'e'){
         return false;}
      else if(letter == 'i'){
         return false;}
      else if(letter == 'o'){
         return false;}
      else if(letter == 'u'){
         return false;}
      
      //returns true if letter is not a normal vowel
      return true;
      }

   /**
    * counts the number of vowels in a given string
    * @param word of type string
    * @return number of vowels
    */
   public static int vowelCount(String word){
      int vowels = 0;
      int n = 0;
      while (n < (word.length())){
         if (word.charAt(n) == 'a'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'e'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'i'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'o'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'u'){
            vowels++;
            n++;}
         else if(word.charAt(n) == 'y'){
            //if y is at the beginning... increment counter
            if(n == 0){
               n++;
            }
            //increments the vowel counter if y is at the end of a word
            else if(n == word.length() - 1){
               vowels++;
               return vowels;
            }
            else{
               //if y is surrounded by consonants, increment vowel count
               if((isConsonant(word.charAt(n-1)) == true) && (isConsonant(word.charAt(n+1)) == true)){
                  vowels++;
               };
            
            n++;
            }
         }
         
         else{
            n++;};
         }   
      return vowels;         
      }
}




Tester:
Spoiler:

Code: Select all

/**
 *
 * @author Matt Young
 */
import java.io.*;
import java.util.Scanner;

public class Main extends Words{
   public static void main(String args[]) {
      //opens our output file for writing
      try {
         System.setOut(new PrintStream("H:/output.txt"));
         int vowels = 0;
         int wordCount = 0;
         int palindromeCount = 0;
         //tries to open file so we can count words
         //count and echo palindromes
         //count vowels
         try {
            FileReader filename = new FileReader("H:/hamlet.txt");
            Scanner in = new Scanner(filename);
            String input;
            while (in.hasNext()) {
               //grab word from file
               input = in.next();
               //send word to cleanup here
               input = wordCleaner(input);
               //print it if it's a palindrome
               //but greater than 1 character
               if ((input.length()) > 1) {
                  if (isPalindrome(input) == true) {
                     palindromeCount++;
                     System.out.println(input);
                  }
               }
               //finds out how many vowels are in the word
               //and increments our counter
               int vowelsInWord = vowelCount(input);
               vowels += vowelsInWord;

               //increment word count
               wordCount++;
            }
            //echoes our word count
            System.out.println("Word Count: " + wordCount);
            //echoes the vowel count
            System.out.println("Vowel Count: " + vowels);
            //echoes Palindrome Count
            System.out.println("Palindrome Count: " + palindromeCount);
         }
         //catches file open error
         catch (IOException e) {
            System.err.println(e);
         }
         //closes our input file
         System.out.close();

      //closes try statement to our output file
      }
      //prints a stack trace upon setOut failure
      catch (IOException e) {
         e.printStackTrace();
      }
      //closes output file
      System.out.close();

   }//end of main method
   }//end of class


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

Got another one

Postby '; DROP DATABASE;-- » Fri Nov 30, 2007 6:07 am UTC

This one's been bugging the hell out of me for a few days now. It creates three windows, each a child of the previous one. It works fine except the child windows are unable to gain focus. They remain in the grayed-out inactive state no matter what. Mouse, keyboard, ActivateWindow(), SetForegroundWindow() etc, nothing will do it. This seems to be causing all sorts of trouble with controls. Text boxes won't respond to anything except double-click, combo boxes act like they're opening up but don't and manage to block all window messages until Escape or Enter is pressed, etc. I suspect it's all because the controls aren't gaining focus properly.

I can move them, resize them, etc just fine. The only thing that doesn't seem to be working focus. I've tried it on two different machines now.

Spoiler:

Code: Select all

#include <stdio.h>
#include <windows.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK WindowProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   WNDCLASSEX Class;
   unsigned int Style = WS_VISIBLE | WS_OVERLAPPEDWINDOW, ExStyle = 0;
   HWND hWindow[3];
   char* ClassNameStr = "Blah";
   char Title[3];
   MSG WinMsg;
   unsigned int XPos[3] =      {689, 10, 10};
   unsigned int YPos[3] =      {360, 10, 10};
   unsigned int Width[3] =      {200, 160, 120};
   unsigned int Height[3] =   {200, 160, 120};


   //Create and register class
   Class.cbSize = sizeof(WNDCLASSEX);
   Class.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
   Class.lpfnWndProc = WindowProc;
   Class.cbClsExtra = 0;
   Class.cbWndExtra = 0;
   Class.hInstance = hInstance;
   Class.hIcon = NULL;
   Class.hCursor = NULL;
   Class.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE + 1;
   Class.lpszMenuName = NULL;
   Class.lpszClassName = ClassNameStr;
   Class.hIconSm = NULL;

   if(!RegisterClassEx(&Class))
   {
      printf("Register class failed\n");
      return 1;
   }


   //Create windows, each child of the previous one
   for(int i=0; i<3; i++)
   {
      sprintf(Title, "#%d", i + 1);
      hWindow[i] = CreateWindowEx(ExStyle, ClassNameStr, Title,
            Style, XPos[i], YPos[i], Width[i], Height[i],
            i ? hWindow[i - 1] : NULL, NULL, hInstance, 0);
      if(!hWindow[i])
      {
         printf("Create window %d failed\n", i);
         return 1;
      }
      Style |= WS_CHILD;
   }


   //Main loop
   while(IsWindow(hWindow[0]))
   {
      for(int i=2; i>=0; i--)
      {
         //Process messages
         while(PeekMessage(&WinMsg, hWindow[i], 0, 0, PM_REMOVE))
         {
            TranslateMessage(&WinMsg);
            DispatchMessage(&WinMsg);
         }
      }
      Sleep(20);
   }

   DestroyWindow(hWindow[0]);
   DestroyWindow(hWindow[1]);
   DestroyWindow(hWindow[2]);

   return 0;
}


LRESULT CALLBACK WindowProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
   return DefWindowProc(hWnd, Message, wParam, lParam);
}

The result:
Image
#2 and #3 will not take focus, ever. I've tried all manner of different styles, handling messages, etc.
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

User avatar
Eleyras
Posts: 131
Joined: Sat Oct 27, 2007 6:56 am UTC
Location: the computer lab

Re: The "IT DOESN'T WORK!" thread

Postby Eleyras » Fri Nov 30, 2007 10:51 am UTC

Does HTML/CSS count?

I've agreed to help design a website and have picked up handy dandy reference books, forging full speed ahead with notepad to play around with things in my documents folder. Saves me from having to be connected to the internet. My problem? Things are working fine in IE, but not Firefox. Since I browse in firefox, this is not acceptable. Are their standards _THAT_ different?
At some point, I will remember to sig quotes I find amusing or something.

...once I stop laughing.

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

Re: The "IT DOESN'T WORK!" thread

Postby Rysto » Fri Nov 30, 2007 6:40 pm UTC

Standards! Ha! IE laughs at such trivial things such as standards.

Rubby
Posts: 9
Joined: Fri Oct 26, 2007 12:37 am UTC

Re: The "IT DOESN'T WORK!" thread

Postby Rubby » Sat Dec 01, 2007 6:34 pm UTC

I was writing a PHP script a couple of days ago. The script I was working on was about 200 lines long and it just wouldn't work. I was going through each line, sending it through debuggers and everything and couldn't figure it out. After about 2 hours (making the time about 3:00 am) I noticed the very first line of code:

Code: Select all

isset(!$_GET['something'])?$some_var=null:$some_var=$_GET['something'];

and I really needed

Code: Select all

!isset($_GET['something'])?$some_var=null:$some_var=$_GET['something'];

I nearly threw my monitor due to frustration at my own stupidity.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests