Forum-coding - starting the game

I got an idea that might be very constructive and educational.
Short story: to write code, as a group.

If you don’t like the idea of taking 5-10 min to write some code, just stop reading
because this is going to be long - as you may see :slight_smile:

Details:

  1. One thread, like “forum-coding: our shopping cart” that contains:
  • specifications (what we want to do - more than 10 items)
  • some functional starting code (it can be a class or not) but not more than 30 lines
  1. Any post from this thread will only contain
 stuff. No useless comments,
no "that's not OK" or "I don't like your idea"
3. The next post will have:
- the code
- list of solved items from the starting thread (OR not, if nothing was solved).
4. The thread ends when all items are solved.

* before you start coding, add a post with the text "work in progress..." se we
will not have conflicts (two posts at the same time - it happens!)


Example:

[starting] George: 

<?php
class cart {
public $products = array();
}
$cart = new cart;
?>
/*
We need

  • session cart
  • users management
  • wish-list
  • prices
  • discounts

Nothing solved
*/



MIKE: 

<?php
class cart {
public $products = array();
public $users = array();
public function __construct() {

	}
}
$cart = new cart;
/* solved X (just as example) */

?>



GRIG: 

<?php
class cart {
public $products = array();
public $users = array();
private $session = array();
public function __construct( $sessId ) {
$this->session = isset($_SESSION[‘cart’.$sessId]) ? $_SESSION[‘cart’.$sessId] : ‘’;
}
}
$cart = new cart( 23 );
/* solved X (by previous user)
solved Y (by you)
*/
?>




Simple rules:
1. No endless code. No more than 30-50 lines added per post. We need eficient code.
2. Only code, no comments (except solved items), no other texts. Just talk in code!
3. One user cannot post twice in a row
4. Name variables wisely. No $c or $csw vars!!
5. You cannot delete or move code. You can add in front or before, but don't move or delete
Example:

// user 1
$a; $b;

// user 2
$c; $a; $b;
// or
$a; $b; $c;

// DO NOT POST
$b; $c; $a; - that means moving


6. The users will not block others code. So, do not:

class cart {
public $products = array();
public $users = array();
private $session = array();
public function __construct( $sessId ) {
return $sessId; // not!
$this->session = isset($_SESSION[‘cart’.$sessId]) ? $_SESSION[‘cart’.$sessId] : ‘’;
}
}
$cart = new cart( 23 );


7. You cannot edit your code. Once you post it, it's there. Someone else may work at something at that time.
8. The code must not have errors, so the next user will only copy-paste it and add own code.
[if you think at more rules, just add here and I'll edit the post]

If someone breaks some rule, in the next post the user will only add a link to [b]this[/b] thread and type
(rule no. 5 was broken) and use the previous version of the code, the one that it's OK.

The challenge will be huge: some, that are at the beginning will learn stuff and try to manage to
understand the "language". Others, that know stuff, will get angry but learn how to wisely fix things.

I've created this thread as an initiative (I will post it on other forums too) to check if it works as
an educational program. It's a win-win challenge, in my opinion.

Now, just post here if you'd like to take 2-5 minutes to type some code in some of those threads.
If I get more than 3 "raised hands", I'll post my first game-thread.

Happy coding!