简体   繁体   中英

On your very first program, which construct hooked you on programming?

对我来说,这是If声明,我很兴奋,从那以后我相信计算机非常聪明,或者我至少可以让它看起来很聪明。

For many of us who were introduced to computers in the late 70's or early 80's, the first program we saw looked like this:

10 PRINT "Commodore sucks!  "
20 GOTO 10

("Commodore" could be replaced with "Apple", "Atari" or "TRS-80").

GOTO is awesome.

Answer #2 :)

The actual language construct that first really fascinated me was recursion. The problem

Write a function named SumDigits which summed the digits of a number. Example: SumDigits(1234) -> 10

At first I wrote a very long iterative solution. But after awhile I came up with this answer.

string SumDigits(int value) {
  if ( value > 10 ) {
    return SumDigits(value/10) + (value%10);
  }
  return value;
}

The succinctness of the answer amazed me and I instantly found a new love in recursion and terse programming.

It only took a couple of weeks though to learn the evils of recursion :)

Making the computer obey me. Awesome.

I also love (love to hate) that the computer will obey even when I'm wrong.


But seriously folks.

I was hooked when:

  • I saw that you can do rich and dynamic things with code.
  • That the machine is generally consistent.
  • That programming is like math in the sense that for all the "it depends" out there, we still have more than our fair share of questions with actual, provable answers.
  • That I could automate menial tasks with logic and loops.

Started out in QBasic , so, I think it was something along:

INPUT "What's your name?", a$
PRINT "Hi, "; a$; "!"

Being able to show something on the screen with PRINT was enough to get me excited about programming. Interactivity using INPUT was icing on the cake!

Pointers.

When I started programming in Turbo Pascal, I really couldn't understand, how the heck they write big programs. Memory was limited, and whatever I was trying to do - I would often hit the stack limits.

When I finally was introduced to pointers I was finally hooked, because I could finally start making something big! Not that I made anything big, but... :)

When I first started learning programming with QBASIC the whole idea of flow control using if statements and loops was great. I think it was just a few days after I learned about the if statement that I built my first "Choose your own adventure" game. Looking back I know it must have been horribly inefficient and massive in terms of lines of code, but the fact that I could branch the story using nothing but if statements was wonderful.

Lambda expressions

Been programming my nearly my whole life, but even now find excitement in new things like Lamdba expressions.

 MyList.Any(p => p.IsCurrent)

Hmm.. love it.

For me, it wasn't a specific syntax - it was finding out I could break out and change ZX Spectrum games - I guess discovering source code is what got me hooked.

Then, when I actually started programming, and was copying code from books, being able to customise what was in the book and have the program still work, but how I wanted.

? "HELLO WORLD"

From my first BASIC book (BASIC for kids I believe):

10 INPUT A
20 INPUT B
30 LET C = A + B
40 PRINT C

That was on the cover of the book, and I was thrilled with the possibilities (it could do my homework!)... It took me like a couple of weeks to grasp that simple concept, but once I got it, the world of programming opened up for me.

I really fell in love with programming languages once I discovered comments. You can do all kind of stuff with it, like

// a commment!
int /* whoa, an inline comment! */ a;

;)

For Loops + Arrays did it for me. Once I realized that I could loop through an arbitrarily large set of things and do something to each of them, it all started to come together.

绝对是FOR循环 - 在6岁的时候,有了这个lil'logO Turtle从绘制一条线到绘制一个正方形到绘制一个圆圈就是把我从用户变成程序员所需要的。

Clear case, the loop. Specifically looping in Gwbasic. Just for fun I wanted to print all the numbers from 0 to 100 on the screen. So I started:

10 print 1
20 print 2
30 print 3
40 print 4

At some point I thought WTF or something similar. There must be a better way. So I asked someone (perhaps a teacher or some fellow pupil) who then introduced me to the magics of variables and the loop . That must have been the moment I got hooked.

10 SET i = 0
20 IF i > 100 THEN GOTO 60
30 PRINT i
40 SET I = I + 1
50 GOTO 20
60 REM END LOOP

Thats 6 lines instead of 100!!! That was just so much better. Sorry if I got the syntax not exactly right. :-) I am really fond of that moment.

The first Fortran code I wrote had an if statement in it, and was one of the most fascinating things I had seen at the time. Something like this one

     integer n

     n = 1
  20 if (n .le. 100) then
        n = 2*n
        write (*,*) n
        goto 20
     endif

When I was first learning, I think arrays for sure. Before that I really just thought in terms of single variables. When I learned about arrays, I was able to do a lot lot more with my qbasic :).

Now I have all sorts of data structures available, not just arrays :)

For me it was Pointers.

Whilst I won't even pretend to fully understand pointers it was the first time that I really got stuck with programming. After messing around with Visual Basic 6 and server-side scripting languages I moved onto C, picked up the bare basics, then met pointers.

During that lecture I can remember peoples reaction to pointers. Self-proclaimed programming gods cowered in fear, those that knew little started reading the job ads in the local papers. I actually remember one girl in my class saying "whaaa?"

Many programmers get a wake-up call when they hit pointers. The programming world has just introduced you to the world of Computing and if you've only really just met you'll find very little to talk about.

I remember the first computer problem that truly fascinated me. It was a problem I got in my highschool programming class.

Write a program that will read a number from the console

Why did that fascinate me? Well it didn't at first. I wrote a quick and dirty program that did the deed but then the teacher did something quite unexpected. She entered "a" into the program and it died a horrible death.

It took me the rest of the day to deal with evil input but eventually I got it working. This process completely hooked me on the idea of program correctness.

IF-GOTO.

No joke. I was hooked long before I got such a language as had pointers.

I had already written pointer-like algorithms using array indexes by that point.

Function pointers in C.

First I learned C, but not function pointers.

Then I began programming in assembler for about a semester in the university. I used function pointers then without even knowing about them. Somehow they seem like a natural thing in assembler for me. I had to explain them to my teachers a few times, because they didn't understand them :).

Then, I came back to C, and revelation hit me.

Now I laught at Java methods, generics, late polymorphism and such said "magic" things.

PRINT 3 + 4
The Computer said 7. And all this was visible on my parents TV. ON A TV!!! Can you imagine that? I was imediately hooked. You could tell a machine what to do and you could see on a TV. Wow.

Backgound: My dads employer bought a small computer (Robotron KC 85/1) for the engineers to get in touch with this technology. They could take it home to play with it at the weekend. So my dad brought it home and all he new about it was how to connect it and how to turn it on. One of his collegues told him the trick with the "PRINT" command and the addition of numbers. He showed me and I was hooked. This was about 1986 when I was 12. I am still hooked for basicly the same reason (telling a machine what to do).

qBasic, when I was around 10 - 12 i started making a copy of that "The doctor asks you weird questions"-game. Which ended up as a lot of nasty questions. That's when i knew I wanted to work with computers.

A couple of years later i started playing with HTML and PHP, giving me a couple of customers and i started a company, that's when i knew i could get bloody rich on this :)

I've only been programming for about a year, so for me, it was LINQ. I looked at codes in books that exposed the query string to the DB, and thought "wow, that's kind of lame.". The I met LINQ and we have been happily married ever since.

When DBase II allowed me to print records to a text file AND stick exactly the right typesetting codes pretty much where I wanted -- before them, inside them, behind them, around them. I can still feel the chill on the back of my neck. WOW a whole whole typesetting system right here in my tiny computer! Warm up the 300 baud modem and send this file straight to an 8-inch disk and run it through a Compugraphic. Yards of beautifully shiny photo-type paper with all the letters in the right place. I do not deserve this happiness ...

Mine was goto in basic. I thought it was incredible you could make the program jump where ever you wanted it to. Only later did I realize with great power comes great responsibility.

for or while循环,因为我可以在分子动力学模拟中使用它,我不必一次一个地进行计算

What really made me hooked on programming was the following lines of x86 assembler:

mov ax, 13h
int 10h
mov ax, 0a000h
mov es, ax

When I got how easy it was to draw things by messing with the video memory, all the other stuff I've learned was suddenly useful for something.

Inspired the word

BASIC B eginners A ll P urpose S ymbolic I nstruction C ode

I found ++ to be fascinating in high school.

Everyone else knew Basic, Pascal, etc. But i++ was code ! And code that only I knew!

And such tiny changes could have very important effects: ++i is different in many important ways from i++. And ++ translates so directly all the way down to machine code. So by learning this, I had direct access to the CORE of the MACHINE. Imagine the power!

Learning about this made me want to learn all the other strange operations and corners of the C language.

TRS-80图形

POKE 15360, 191

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM