spectere.net

Retired => Retired Boards => |)|)R FR3|< => Topic started by: Spectere on June 09, 2008, 03:07:06 AM

Title: private static bool GetTrue() { return true; }
Post by: Spectere on June 09, 2008, 03:07:06 AM
http://thedailywtf.com/Articles/Seeking-the-Truth.aspx (http://thedailywtf.com/Articles/Seeking-the-Truth.aspx)

I literally facepalm'd.
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 09, 2008, 08:02:20 AM
Haha, that was awesome.
Title: Re: private static bool GetTrue() { return true; }
Post by: Sneaky on June 09, 2008, 04:36:19 PM
Gotta love how anyone who knows any bit of coding thinks they're the kind shit of nerds/programmers. I fucking hate that shit.

LETS START AN E PEEN CONTEST TO SEE WHO CAN COME UP WITH THE MOST VARIATIONS OF THIS CODE ALOALOOLOLOL JUAJUAJUAJUAJ JEJEJEJEJE

:l
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 09, 2008, 06:05:14 PM
LETS START AN E PEEN CONTEST TO SEE WHO CAN COME UP WITH THE MOST VARIATIONS OF THIS CODE ALOALOOLOLOL JUAJUAJUAJUAJ JEJEJEJEJE

private static bool GetTrue() { return true; }
private static bool GetTrue() { return !false; }
private static bool GetTrue() { if(1==1) return true; else return false; }
private static bool GetTrue() { if(0==1) return false; else return true; }

...etc...
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 09, 2008, 07:11:42 PM
private static bool GetTrue() { '0' < '1' ? return 1 : return 0; }
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 09, 2008, 10:53:48 PM
Ah, testing for truth with random, magic chars!  Nice touch.  I would have probably done something silly like this: 'A' < 'a' ? return true : return false; but hey, whatever works.

One little nitpick -- that code won't compile.  For the language bool type you have to use "true" and "false".  If it were a BOOL (like what Win32 uses, being a C-friendly API; note the caps) then everything would be kosher.
Title: Re: private static bool GetTrue() { return true; }
Post by: Zakamiro on June 10, 2008, 06:40:36 AM
Gotta love how anyone who knows any bit of coding thinks they're the kind shit of nerds/programmers. I fucking hate that shit.

LETS START AN E PEEN CONTEST TO SEE WHO CAN COME UP WITH THE MOST VARIATIONS OF THIS CODE ALOALOOLOLOL JUAJUAJUAJUAJ JEJEJEJEJE

:l

reminds me of the thread spec and I shat up in emilio's comedy barn.
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 10, 2008, 06:49:06 AM
reminds me of the thread spec and I shat up in emilio's comedy barn.

We are very good at shitting, yes.
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 10, 2008, 08:13:17 AM
Ah, testing for truth with random, magic chars!  Nice touch.  I would have probably done something silly like this: 'A' < 'a' ? return true : return false; but hey, whatever works.

One little nitpick -- that code won't compile.  For the language bool type you have to use "true" and "false".  If it were a BOOL (like what Win32 uses, being a C-friendly API; note the caps) then everything would be kosher.

I was sorta assuming it was gonna be written in plain C/C++. Back in the old books I read, I thought I remembered something about C/C++ not caring what you passed into a bool because when it saw bool, it would just check for zero/non zero, regardless of what it actually was.

I haven't worked in C/C++ in fucking forever though.
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 10, 2008, 02:48:55 PM
C doesn't have the bool type and C++ does, in fact, seem to allow you to use bool as an unsigned integer (tested with Visual C++ 2008 Express).  I think I've been using C# too much. :P

I seem to recall getting a compiler error from something when I tried to compare a bool to an int.  I might have had the compiler set to a really pedantic setting, though.
Title: Re: private static bool GetTrue() { return true; }
Post by: Zakamiro on June 10, 2008, 05:19:04 PM
I don't want to derail the thread, but someone talked shit about me trying to learn visual c++ 2005. They said it was to "old" and I should switch to a "better" and "newer" language because apparent c/c++ were outdated. Well, C needs way less code than nearly every language out there (except for obviously ASM, machine), and is a much better performer than C#.

Quote from: http://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Performance
Performance

C# programs, like all programs written for the .NET and other virtual machine environments such as Java, tend to require more system resources than functionally similar applications that access machine resources more directly.

Anyway, object-oriented design is still a little new for me, most of my experience comes from mIRC code, where the most object oriented design you get comes from hash tables and ini files. Ehm. Yeah. Thoughts/opinions?
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 10, 2008, 06:14:04 PM
Naturally.

The real deal with languages like that is that you have to find the right balance of speed and convenience for what you want to do.  C# is a hell of a lot easier than C++ which is a hell of a lot easier than C.
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 11, 2008, 08:08:26 AM
Naturally.

The real deal with languages like that is that you have to find the right balance of speed and convenience for what you want to do.  C# is a hell of a lot easier than C++ which is a hell of a lot easier than C.

Agreed.
I learned C++, I've never really known what the differences were between C and C++, to be honest. I do know that c people use printf where lazy C++ users use cout. And Strings are new to C++, but that's all I really know, lol.
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 11, 2008, 06:58:48 PM
Lessee, C++ introduces classes (which include the ability to overload operators), uses streams for most IO functions (cout, fout, etc), adds the bool type, templates, and I think that's about it (though those changes alone are quite significant).

The string type isn't technically a built-in type.  It's part of the standard C++ library.  The new features that C++ offers (namely, classes and operator overloading) are what allows them to appear to be integrated into the language.
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 11, 2008, 10:27:59 PM
Ok, yeah, i knew most of those, i just didn't think of it.
Title: Re: private static bool GetTrue() { return true; }
Post by: Zakamiro on June 12, 2008, 06:49:10 AM
So, is it a worthy investment to learn C++? or would C/C# be a better alternative?

(no delphi, pascal, java, fortran, cobol, basic for me (yet) please & thanks)
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 12, 2008, 08:12:03 AM
Uhh, Java and C++ and C# are very similar. I've done quite a bit of work in Java, and actually really like the language, despite it's shortcomings. Networking is ridiculously easy in it. Networking in C++ is a PAIN, and I think C#'s networking is pretty much on par with Java's for ease of use.

If you're just learning a language to program, C# would probaby be your best bet, though C++ requires less code to do the real basic stuff (like console I/O) (of course, you can pare down C# programs quite a bit by not using the default projects from Visual Studio, lol.)

The first code I ever touched was VB6. Then I learned C++. After that, I took some highschool programming, and covered VB6 again, and learned Java. I also taught myself Turing, since they had it there (fun language, and REALLY FUCKING QUICK to write stuff in. I actually made a simple encryption engine for a small programming contest in it, despite only learning it in my spare time on school computers).

For simple programming concepts, VB or Turing (if you can find the compiler program) are simple as hell. However, VB all around blows for a lot of stuff, and Turing has syntax that isn't like C/C++.

All in all, aside from lisp, fortran, cobol, ASM, and brainfuck, you can begin learning with pretty much any language.
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 12, 2008, 09:21:34 AM
:snip: C++ and C# are very similar.

Only in that you can migrate from one to the other without much of a problem.  C# and C++ are worlds apart as far as functionality and, for the matter, ease of use is concerned.  C# is closer to Java than C/C++.

If you're just learning a language to program, C# would probaby be your best bet, though C++ requires less code to do the real basic stuff (like console I/O)

Not really:

System.Console.WriteLine("Hello world!");

Stick that in main() and, regardless of references, you have Hello World in C#.  You need two lines to do the same thing in C++ (not including the main function declaration).

All in all, aside from [...] fortran [...] you can begin learning with pretty much any language.

(http://files.spectere.net/pictures/photos/fortran-book.jpg)

Code: [Select]
INTEGER FLAG
100 READ(1,100) A,B,C,LC
IF(LC-9) 1,99,1
FORMAT(3F10.0,T80,I1)
10 CALL QUAD(A,B,C,X1,X2,FLAG)
WRITE(3,11) A,B,C
11 FORMAT('0A =',F11.0,2X,'B =',F11.0,2X,'C =',F11.0)
IF(FLAG-1) 20,30,20
20 WRITE(3,13) X1,X2
13 FORMAT('+',T50,'X1 =',F11.3,2X,'X2 =',F11.3)
GO TO 100
99 STOP
END

SUBROUTINE QUAD(A,B,C,X1,X2,FLAG)
INTEGER FLAG
FLAG=0
IF(A) 1,20,1
1 DISC=B**2-4.*A*C
IF(DISC) 30,2,2
2 X1=(-B+SQRT(DISC))/(2.*A)
X2=(-B-SQRT(DISC))/(2.*A)
RETURN
20 X1=-C/B
X2=X1
RETURN
30 FLAG=1
RETURN
END

YEAH FORTRAN!
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 12, 2008, 09:27:49 AM
COBOL = Completely Obsolete, Boring Old Language.

There was one for FORTRAN, but I've forgotten :/
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 12, 2008, 12:54:54 PM
Don't knock COBOL too badly; it's still in semi-heavy use today.  Also, how many standard languages have programs that look like this?

Code: [Select]
       IDENTIFICATION DIVISION.
       PROGRAM-ID.    BOTTLE99.
       AUTHOR.        BILL BASS.
       DATE-WRITTEN.  APR 2008.
       DATE-COMPILED.
      *REMARKS.
      ******************************************************************
      * PURPOSE:
      *   THIS IS A DEMONSTRATION SAMPLE OF A COBOL II PROGRAM.
      *   IT WRITES AN 80 COLUMN OUTPUT FILE CONTAINING THE LYRICS OF
      *   THE SONG "99 BOTTLES OF BEER ON THE WALL".  IT DOES NOT NEED
      *   TO BE AS COMPLEX AS IT IS.  THIS WAS NOT AN ATTEMPT TO WRITE
      *   A "SHORT" PROGRAM OR A "MOST EFFICIENT" PROGRAM.  IT WAS
      *   INTENDED TO SERVE AS AN EXAMPLE OF WHAT ONE MIGHT COMMONLY
      *   SEE IN A "TYPICAL" MAINFRAME COBOL PROGRAM.
      ******************************************************************
       ENVIRONMENT DIVISION.
      ******************************************************************
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT LYRICS-FILE              ASSIGN TO LYRICS.
      ******************************************************************
       DATA DIVISION.
      ******************************************************************
       FILE SECTION.
       FD  LYRICS-FILE
           LABEL RECORDS ARE STANDARD
           RECORDING MODE IS F
           BLOCK CONTAINS    0 RECORDS
           DATA RECORD IS LYRICS-REC.

       01  LYRICS-REC                      PIC X(80).
      *
       WORKING-STORAGE SECTION.
       01  WORK-AREAS.
           05 WS-LYRICS-WRITTEN            PIC S9(8) COMP VALUE ZERO.
           05 WS-BOTTLE-NUM                PIC S9(4) COMP VALUE ZERO.
           05 WS-WHEN-COMPILED.
              10 WS-COMP-DATE.
                 15 WS-COMP-YEAR           PIC 9(4) VALUE ZERO.
                 15 WS-COMP-MON            PIC 9(2) VALUE ZERO.
                 15 WS-COMP-DAY            PIC 9(2) VALUE ZERO.
              10 WS-COMP-TIME.
                 15 WS-COMP-HOUR           PIC 9(2) VALUE ZERO.
                 15 WS-COMP-MIN            PIC 9(2) VALUE ZERO.
                 15 WS-COMP-SEC            PIC 9(2) VALUE ZERO.
                 15 WS-COMP-HSEC           PIC 9(2) VALUE ZERO.
                 15 WS-COMP-TZ-DIR         PIC X(1) VALUE SPACES.
                 15 WS-COMP-TZ-HOUR        PIC 9(2) VALUE ZERO.
                 15 WS-COMP-TZ-MIN         PIC 9(2) VALUE ZERO.
           05 WS-CURR-DATE                 PIC 9(8) VALUE ZERO.
           05 FILLER                       REDEFINES WS-CURR-DATE.
              10 WS-CURR-YEAR              PIC 9(4).
              10 WS-CURR-MON               PIC 9(2).
              10 WS-CURR-DAY               PIC 9(2).
           05 WS-CURR-TIME                 PIC 9(8) VALUE ZERO.
           05 FILLER                       REDEFINES WS-CURR-TIME.
              10 WS-CURR-HOUR              PIC 9(2).
              10 WS-CURR-MIN               PIC 9(2).
              10 WS-CURR-SEC               PIC 9(2).
              10 WS-CURR-HSEC              PIC 9(2).
           05 WS-DISPLAY-NUM               PIC --,---,--9 VALUE ZERO.
      *
       01  BEER-2-DIGIT.
           05 B2D-BOTTLES-1                PIC 99         VALUE ZERO.
           05 FILLER                       PIC X(30)      VALUE
              ' bottles of beer on the wall, '.
           05 B2D-BOTTLES-2                PIC 99         VALUE ZERO.
           05 FILLER                       PIC X(46)      VALUE
              ' bottles of beer.'.
      *
       01  BEER-1-DIGIT.
           05 B1D-BOTTLES-1                PIC 9          VALUE ZERO.
           05 FILLER                       PIC X(30)      VALUE
              ' bottles of beer on the wall, '.
           05 B1D-BOTTLES-2                PIC 9          VALUE ZERO.
           05 FILLER                       PIC X(48)      VALUE
              ' bottles of beer.'.
      *
       01  BEER-1-MORE.
           05 FILLER                       PIC X(30)      VALUE
              '1 bottle of beer on the wall, '.
           05 FILLER                       PIC X(50)      VALUE
              '1 bottle of beer.'.
      *
       01  BEER-NO-MORE.
           05 FILLER                       PIC X(37)      VALUE
              'No more bottles of beer on the wall, '.
           05 FILLER                       PIC X(43)      VALUE
              'no more bottles of beer.'.
      *
       01  TAKE-2-DIGIT.
           05 FILLER                       PIC X(34)      VALUE
              'Take one down and pass it around, '.
           05 T2D-BOTTLES-1                PIC 99         VALUE ZERO.
           05 FILLER                       PIC X(44)      VALUE
              ' bottles of beer on the wall.'.
      *
       01  TAKE-1-DIGIT.
           05 FILLER                       PIC X(34)      VALUE
              'Take one down and pass it around, '.
           05 T1D-BOTTLES-1                PIC 9          VALUE ZERO.
           05 FILLER                       PIC X(45)      VALUE
              ' bottles of beer on the wall.'.
      *
       01  TAKE-1-MORE.
           05 FILLER                       PIC X(34)      VALUE
              'Take one down and pass it around, '.
           05 FILLER                       PIC X(46)      VALUE
              '1 bottle of beer on the wall.'.
      *
       01  TAKE-NO-MORE.
           05 FILLER                       PIC X(34)      VALUE
              'Take one down and pass it around, '.
           05 FILLER                       PIC X(46)      VALUE
              'no more bottles of beer on the wall.'.
      *
       01  BUY-SOME-MORE.
           05 FILLER                       PIC X(35)      VALUE
              'Go to the store and buy some more, '.
           05 FILLER                       PIC X(45)      VALUE
              '99 bottles of beer on the wall.'.
      *
       01  BLANK-LINE                      PIC X(80)      VALUE SPACES.
      ******************************************************************
       PROCEDURE DIVISION.
      ******************************************************************
           ACCEPT WS-CURR-DATE           FROM DATE YYYYMMDD
           ACCEPT WS-CURR-TIME           FROM TIME
           MOVE FUNCTION WHEN-COMPILED     TO WS-WHEN-COMPILED
      *
           DISPLAY '****************************************'
                   '****************************************'
           DISPLAY '**** BEGIN PROGRAM BOTTLE99'
           DISPLAY '**** COMPILED: '
                   WS-COMP-YEAR '/' WS-COMP-MON '/' WS-COMP-DAY ' '
                   WS-COMP-HOUR ':' WS-COMP-MIN ':'
                   WS-COMP-SEC  '.' WS-COMP-HSEC
           DISPLAY '**** START AT: '
                   WS-CURR-YEAR '/' WS-CURR-MON '/' WS-CURR-DAY ' '
                   WS-CURR-HOUR ':' WS-CURR-MIN ':'
                   WS-CURR-SEC  '.' WS-CURR-HSEC
           DISPLAY '****************************************'
                   '****************************************'
           DISPLAY '*'
      *
           OPEN OUTPUT LYRICS-FILE
      *
           MOVE 99                         TO B2D-BOTTLES-1
           MOVE 99                         TO B2D-BOTTLES-2
           WRITE LYRICS-REC              FROM BEER-2-DIGIT
           ADD +1                          TO WS-LYRICS-WRITTEN
      *
           PERFORM 1000-MATCHING-VERSES    THRU 1000-EXIT
               VARYING WS-BOTTLE-NUM FROM 98 BY -1
               UNTIL WS-BOTTLE-NUM < 2
      *
           WRITE LYRICS-REC              FROM TAKE-1-MORE
           WRITE LYRICS-REC              FROM BLANK-LINE
           ADD +2                          TO WS-LYRICS-WRITTEN
      *
           WRITE LYRICS-REC              FROM BEER-1-MORE
           WRITE LYRICS-REC              FROM TAKE-NO-MORE
           WRITE LYRICS-REC              FROM BLANK-LINE
           ADD +3                          TO WS-LYRICS-WRITTEN
      *
           WRITE LYRICS-REC              FROM BEER-NO-MORE
           WRITE LYRICS-REC              FROM BUY-SOME-MORE
           ADD +2                          TO WS-LYRICS-WRITTEN
      *
           CLOSE LYRICS-FILE
      *
           DISPLAY '****************************************'
                   '****************************************'
           DISPLAY '**** RUN STATISTICS FOR PROGRAM BOTTLE99'
           DISPLAY '****************************************'
                   '****************************************'
           DISPLAY '*'
           MOVE WS-LYRICS-WRITTEN          TO WS-DISPLAY-NUM
           DISPLAY '* LYRICS RECORDS WRITTEN = ' WS-DISPLAY-NUM
           DISPLAY '*'
      *
           DISPLAY '****************************************'
                   '****************************************'
           DISPLAY '**** END PROGRAM BOTTLE99'
           ACCEPT WS-CURR-DATE           FROM DATE YYYYMMDD
           ACCEPT WS-CURR-TIME           FROM TIME
           DISPLAY '**** ENDED AT: '
                   WS-CURR-YEAR '/' WS-CURR-MON '/' WS-CURR-DAY ' '
                   WS-CURR-HOUR ':' WS-CURR-MIN ':'
                   WS-CURR-SEC  '.' WS-CURR-HSEC
           DISPLAY '****************************************'
                   '****************************************'
      *
           GOBACK.
      *****************************************************************
      *    THIS PARAGRAPH WRITES THE FIRST 98 MATCHING VERSES
      *****************************************************************
       1000-MATCHING-VERSES.
      *****************************************************************
           IF WS-BOTTLE-NUM > 9
               MOVE WS-BOTTLE-NUM          TO T2D-BOTTLES-1
               MOVE WS-BOTTLE-NUM          TO B2D-BOTTLES-1
               MOVE WS-BOTTLE-NUM          TO B2D-BOTTLES-2

               WRITE LYRICS-REC          FROM TAKE-2-DIGIT
               WRITE LYRICS-REC          FROM BLANK-LINE
               WRITE LYRICS-REC          FROM BEER-2-DIGIT
               ADD +3                      TO WS-LYRICS-WRITTEN
           ELSE
               MOVE WS-BOTTLE-NUM          TO T1D-BOTTLES-1
               MOVE WS-BOTTLE-NUM          TO B1D-BOTTLES-1
               MOVE WS-BOTTLE-NUM          TO B1D-BOTTLES-2

               WRITE LYRICS-REC          FROM TAKE-1-DIGIT
               WRITE LYRICS-REC          FROM BLANK-LINE
               WRITE LYRICS-REC          FROM BEER-1-DIGIT
               ADD +3                      TO WS-LYRICS-WRITTEN
           END-IF
           .
       1000-EXIT. EXIT.

NOT ENOUGH!  ...thankfully
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 12, 2008, 03:37:42 PM
Wow, an "english" programming language. Too bad it takes too much code to be practical :/
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 12, 2008, 06:34:13 PM
Indeed.  The programmers in the last 50s and 60s were masochists.

In all honesty, the COBOL parser is pretty impressive.  You can literally make a lot of statements as terse or verbose as your little black heart desires.  One example that the Wikipedia page has deals solving the quadratic equation (x = (-b
Title: Re: private static bool GetTrue() { return true; }
Post by: Zakamiro on June 12, 2008, 11:22:08 PM
so, visual c++ 2005. worthy investment?
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 12, 2008, 11:42:20 PM
Ugh, quite honestly, if you're going to learn a language, don't shell out money to do so. You can obtain VC++ through a PERFECTLY LEGITIMATE site, or you could use one of the MANY free C++ IDEs.
Title: Re: private static bool GetTrue() { return true; }
Post by: Spectere on June 13, 2008, 12:12:45 AM
You can obtain VC++ through a PERFECTLY LEGITIMATE site, or you could use one of the MANY free C++ IDEs.

What are you talking about?  Microsoft's been providing free development tools for years:

http://www.microsoft.com/express/ (http://www.microsoft.com/express/)

So no, don't spend money on it when you can download it, legally, for free.  The only thing that the express editions lack are mainly enterprise-level tools (Crystal Reports, versioning control, etc).  You can even get an express edition of SQL Server if you want.
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 13, 2008, 12:26:44 PM
I forgot about express. Plus, why get 2005 express when they now have 2008 express?
Title: Re: private static bool GetTrue() { return true; }
Post by: Zakamiro on June 14, 2008, 09:18:44 AM
I actually have a legit copy of visual studio 2005 pro or w/e. pretty interesting when you use both vbasic and c++ to work on the same project in it.  I think I'm going to go read through my books and learn it. :>


(probably both my C++ Primer, 3rd Ed. and Ivor Horton's Beginning Visual C++ 2005.)

Edit:

I'll make a timeline thread about my learnings of c++. Here's the link:  http://www.spectere.net/smf/index.php?topic=583.0
Title: Re: private static bool GetTrue() { return true; }
Post by: Bobbias on June 14, 2008, 10:07:43 AM
Nice link, lol.