• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How many ways could a certain program be developed?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79701
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79701
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 34
1
MyEclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79701
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 34
1
MyEclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79701
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Crusading Chameleon likes the size of this ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic