• Post Reply Bookmark Topic Watch Topic
  • New Topic

How many ways could a certain program be developed?  RSS feed

 
Jj Taylor
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry if this is a stupid question, I've been away from programming for a while and just got back into it.

I'm interested is there more than one way a game like pong for example could be programmed? or would it always be near enough 95% the same code (methods, libraries etc).. Excluding named variables of course hence the 95% . Lets say if it was a pong to be developed using JFrame...


Basically would there be a number of ways to code it to do that job of the classic pong? or even space invaders, tetris etc

I'd be interested to hear some feedback on this from the pros to help with my learning & confidence carrying on

Thanks
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it isn't a stupid question.

Of course there are lots of ways to program any application. Unfortunately, a large proportion are incorrect. A game, even noughts‑and‑crosses, would be completely different programmed procedurally (e.g. in C) from in Java® (OO), even if the end result looks the same to the user.
 
Jj Taylor
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell, your good at replying and a big help to newcomers (Last time I posted was beginning of last year and you help somewhat then)

I didnt explain it properly, I mean with just the programming language Java alone, not any other language..

Lets pick a different simple game.... Snake for example...

If we was to do this with in JFrame, and we set 10 students/people from different schools from around the world to make a game like this with set goals so its near the same gameplay......

Would you see a lot of difference in the code?

And lets step up a bit, 2 students or persons from different schools on a basic version of minecraft 3D picking up grass blocks...

ALL in JAVA by the way

Look forward to your response... It'll help me direct the confidence I'm lacking at the moment..
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too tired to write much at the moment, but yes, two people would produce different code.
 
Jj Taylor
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok cool, well theres a start on the reply and no worries if your tired. If you remember though tomorrow if you could give me a bit more explanation - it doesn't have to be much.

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's not really much to explain. There are so may possible permutations that it would be unlikely to impossible for two people to produce the exact same code for any non-trivial program.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look around this forum for a while, there's plenty of examples of nearly-functional code which people have posted with questions. Often this is code about which other people have said "OMG you should have done it this completely different way instead". So yes, the phrase is "There are many ways to skin a cat".
 
Jj Taylor
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm starting to grasp it now, I've posted a link on a thread just now about a games tutorial and they way they do there VK_UP keyboard stuff they use SWITCH/CASE when others use IF and more..

This also gives me a push towards sticking with it as theres endless possibilitys wihich make it fun to work with and never get bored (as such)

Thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any program can be written in almost an infinite number of ways.

Compare it to this: Ask two people to write a story about whatever subject. You will most likely get two stories with a completely different set of sentences and words. It would be very surprising if the two stories would use the same sentences.
 
Ravi Shankar Kumar
Ranch Hand
Posts: 30
1
Java MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

There are two way as per my knowledge an you have to be biased and select one depending up on your skill.
1. Object Oriented Programming
2. Procedural/Functional programming

Thanks
Ravi
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Shankar Kumar wrote: . . .
2. Procedural/Functional programming

Thanks
Ravi
That is at best confusing. Procedural programming and functional programming are very different from each other.
 
Ravi Shankar Kumar
Ranch Hand
Posts: 30
1
Java MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell Ritchie,

I completely agree that both Procedural programming and functional programming is different But in grouping of both this is very different approach from OOP. As per question and programming style I distributed the path of programming style in two generic way which he (Taylor) can follow .

we know that :-

A functional language (ideally) allows you to write a mathematical function, i.e. a function that takes n arguments and returns a value. If the program is executed, this function is evaluated.

A procedural language, on the other hand, performs a series of sequential steps, where the functional program would be nested and included. There's a way of transforming sequential logic into functional logic called continuation passing style. So if i say purely procedural style then obviously this is different that functional .

we are in the java domain so this is a different path called object oriented style .

so we can say that somehow procedure language has functional property and style. So if we will discuss the programming language can you please tell me 'C' language will come in which category?

Thanks
Ravi
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to write functional programs by using recursion only in many non‑functional languages (probably including C and Java), but C is definitely a procedural language.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you ask 10 programmers to write a "Hello World" program, you are likely to get 11 different solutions. For me, one of the most eye-opening tools for seeing how other people solve problems is Project Euler. The problems (at least in the beginning) are fairly straight-forward math problems. But once you've submitted your correct solution, you get access to the forums where you can see all the solutions, in many languages. No two of them will ever be the same. It's very helpful and will show you solutions you never dreamed of. You'll be amazed at the wide variety of solutions to the same problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!