Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    25
  • comments
    26
  • views
    26479

Trying out Go

Sign in to follow this  
Liza Shulyayeva

767 views

A couple of weeks ago I had the genius idea to rewrite SnailLife in Go. I’ve already looked into doing this once before a couple of years ago, but wasn’t really feeling it and stuck with PHP (mostly for nostaligia reasons). Now though, SnailLife is this bloated PHP app. Most of the core functionality is in. After weeks of battling infrastructure issues, when everything was back up and running again, I took a step back and saw how big the app (or rather the 3 apps now) had become. At the same time I’d been reading in passing about Go and became curious, so I figured - why not look into learning Go by rewriting SnailLife? Not because I think Go itself will necessarily make anything better, but because a rewrite might.

The features are mostly already designed, reimplementing them in another language would hopefully let me focus more on improving the overall project structure while learning the new language of choice. Of course, the “learning the new language of choice” part also increases the likelihood of my turning my messy PHP app into a messy Go app as I go, but…it’ll be fun, OK?

Anyway, I’m not yet sure if I’ll stick with the Go port or if I’m just amusing myself for a while before going back to the already largely implemented PHP version. So far I haven’t coded anything snail-specific and have instead been focusing on setting up database-related packages. I’ve made the code public on GitLab for now, though not sure if that’ll change when I go into writing the more snail-specific functionality: https://gitlab.com/drakonka/gosnaillife

When I started the PHP version of SnailLife, I started by building the website and the main functionality that lets users interact with their snails. As time went on this focus switched almost exclusively to the back-end, and to working on functionality that required no user interaction. I realized that this is what the core of the idea was - simulating the actual snails - the brain, organ function, etc - things that the user could eventually influence indirectly, but things that would tick away on their own even if no user was involved. So for the Go version I am not starting with a web front end but with a simple CLI, and focusing on implementing the core of the snail itself first. Eventually I can build whatever front-end I want, or even multiple front-ends if I feel like it. Heck, I could even expose some sort of API for others to make their own apps on top of the simulation (if anyone wanted to, in theory).

Go notes to self

  • Open and close DB connections as little as possible - the driver handles connection pooling for you, you should only really need to do it once.
  • Best way of reusing constructors between tests might be to create some test utilities outside of _test files which are imported only by the tests. Example usage in my case is creating a test db and table to run my mysql and repo tests against, which are in different packages.
  • Every directory is a package. There is no way to structure code in subdirectories without each subdirectory being a separate package.
  • Make use of table driven tests. They allow you to run multiple test cases per test.
  • interface{} is an empty interface and can hold values of any type…avoid passing this around too much, better to learn to structure the code so you don’t have to.
  • Go code looks to be very easy to move around and restructure if needed, so it should be fine to experiment with different project structures as I go.

Current tentative project structure

drakonka/gosnaillife
├── cmd
│   └── snaillifecli
│       └── main.go
├── config
│   ├── dev
│   │   └── database.json
│   └── env.conf
├── lib
│   ├── domain
│   │   ├── item
│   │   └── snail
│   │       ├── snail.go
│   │       └── snailrepo.go
│   ├── infrastructure
│   │   ├── databases
│   │   │   ├── database.go
│   │   │   ├── mysql
│   │   │   │   ├── delete.go
│   │   │   │   ├── insert.go
│   │   │   │   ├── mysql.go
│   │   │   │   ├── retrieve.go
│   │   │   │   ├── tests
│   │   │   │   │   └── mysql_test.go
│   │   │   │   └── update.go
│   │   │   ├── repo
│   │   │   │   ├── repo.go
│   │   │   │   ├── repoutil.go
│   │   │   │   └── tests
│   │   │   │       ├── repo_test.go
│   │   │   │       ├── testmodel_test.go
│   │   │   │       └── testrepo_test.go
│   │   │   └── tests
│   │   │       └── testutil.go
│   │   ├── env
│   │   │   └── env.go
│   │   ├── init.go
│   │   ├── init_test.go
│   │   └── util
│   │       ├── collection.go
│   │       └── err.go
│   ├── interfaces
│   └── usecases

 

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By Entex
      printf("Hello %s", "follow game makers!");
      I'm about to make a game engine, and looking for advice!
      Background
      I have a game engine project I've been thinking about A LOT lately. I know it's gonna be hard, in fact the most challanging programming challange i can think of. With that said, I'm willing to put down the time and effort.
      I'm looking for some advice to keep the project up and running and I'm asking you, game makers! I've so much passion about this project. I've tried making a game engines before, but they have all halted. Some failed because of lack of focus, some failed because of unorganised structure, some failed because of lack of experiance, too big scope, unclear destination... you get the point.
      Now I'm taking a different approach. I'm doing the boring part, pre-planning, researching, etc. That's partly why I'm here, asking you. I'll lay out my plan for you guys. 
      Prerequisites
      I'm gonna try to keep technical terms to a minimum.
      So no spoiling what graphical API's or libraries I'm going to use, that's just asking for political warfare. This is more about the project management, avoiding pitfalls and such.
      The engine is gonna be a 2D engine. When i feel finished (probably in a couple of years) I will expand to 3D, but that's for another time.
      Because it's a game engine it should handle any type of 2D game, sidescrolling, top-down, hell even click-adventures!
      Disclaimer
      Sorry if my english is a bit wacky. Don't judge!
      The Game list(You'll read about it soon.) is just for experience purpose. I don't wanna fall in any kind of legal action because i stole some idea and thus only for personal use. My own ÜBER-awesome-final-game, if ever completed, will be released to the public.
      I first posted this on stackoverflow and was shutdown pretty hard because of too broad topic, understandable. Hoping this is the right forum, I'm just looking for some friendly advice. Kinda hard to get on this internet thingamabob...
      The Plan
      Start simple, work my way towards a more and more advanced game engine. In the end and my long term goal is my very own advanced 2D game(of course built on my engine). As a bonus, I might release the sourcecode of the game engine if I'm happy how it turned out.
      I believe in short term goal too keep my motivation and the feel of progress. But also have major goals to strive for, too always keep myself challanged, get bits and pieces to be proud of and most important have something to look forward to.
      Some of my older tries failed because i lost focus and stopped coding for a while. This time around i think it's best to atleast get a few lines of code every week. My "average goal" is to code for atleast a couple of hours every weekend. Just so i don't stop coding, the worst pitfall (i think).
      My strategy is a list of games to make on my journey. Trying to always have the list as a unit testing tool (Surely I'll have to redo older games when my engine gets up to speed). The list looks a bit like this. 
      Game list, Major hits
      1. Pong
      2. 1 Level platformer (Extremly restricted)
      3. Extended 1 level platformer with screenscrolling, jumping, etc.
      4. Same level with added Sprite/Animation.
      5. Same level with Goomba-like enemies and a finish line.
      6. Multiple levels!
      7. Super Major. A complete, short, single player mario-like game, with different enemies, levels and of course a boss.
      8. Top down 2D game. Bomberman-like
      9. Bomberman-like multiplayer
      10. ... This goes on for a while. Some smaller games, some Super Major

      Smaller technical milestones to start with (I know i said "no technical talk", but this is the extent of it)
      101. Graphical window (Ok, it's not a game but i have to start somewhere right?)
      102. Draw a triangle [Draw objects]
      103. Pong, very hardcoded (No help from the game engine to make collision or so)
      First game PONG
      201. Textures
      202. Simple physics (gravity, friction) collision
      203. Player Controller
      204. ...
      First Platformer: Have a 1 Level platformer were i can jump onto objects and stuff. No enemies, no screenscrolling. Just a super simple platformer.
      301. Animation
      302. Add Screenscrolling
      303. Static enemies
      304. Super simple AI. (Move toward player)
      305. ... Keep on adding so i can complete my list of games
      This is of course not the full list, i just don't want to TL;DR.. If you are still here, you are the GREATEST!
      Some concerns 

      The more I complete games on my list, the longer it will take to complete the next one. The more powerful function, the longer it will take. Multiplayer for instance, is no easy task...
      ADVICE
      Am i on the right track?
      Would you do something different?
      What do you think will work, what is risky?
      Have you tried making a game engine yourself? What kind of pitfalls did you encounter?
    • By Lauren Tuccy
      So my only coding experience is with writing Interactive Fiction games with Inform, so I get the logic and stuff, but, I'm so used to starting with a program with libraries and assets already built in, that I have no idea how to build something from scratch. 
      I'm would like to make this simulation game where the player is a student in a [magic] school, and I've got stats for the students, their personality types, and ideas on how that should effect their performance in class, and experience rates, and all this data in a google spreadsheet, but I have NO idea how to start creating this game on a code level. So, I'm just struggling on finding out how to get started. Can anybody give me some advice?
    • By petya-kurochkin
      Hello, I have a 'join'-function that joins an array's elements to a string. This is what I want:
      vector<int> a = {1,2,3} array<int, 3> b = {1,2,3} cout << join(a) << endl; // "1, 2, 3" cout << join(b) << endl; // "1, 2, 3" So I'm trying to declare the function this way:
      template <typename T, typename C> string join(const C<const T> &arr, const string &delimiter = ", "){ ... } But without any success. I understand, that I could declare it this way:
       
      template <typename T> string join(T &arr){ ... } or this way:
      template <typename Iter> string join(Iter &begin, Iter &end){ ... }
      But I just wonder, is it possible to implement it like:
       
      template <typename T, typename Collection> string join(const Collection<const T> &data){ ... } Thank you!
    • By sausagejohnson
      All games written with Orx have a profile screen that can be called up to monitor for any inefficiencies or bottlenecks.
      Iarwain will be demonstrating the Profile Mode for Orx over twitch tomorrow night at:
      Come along if you're interested to learn about it. There will be an opportunity to cover any topics after the demo.
      Here's some time zones as a guide to when it's on:
      Montréal, Canada      Tue, 11 Dec 2018 at 1:00 am EST     
      Rome, Italy           Tue, 11 Dec 2018 at 7:00 am CET     
      San Francisco, USA    Mon, 10 Dec 2018 at 10:00 pm PST    
      Sydney, Australia     Tue, 11 Dec 2018 at 5:00 pm AEDT    
      You can check other time zones here: https://www.timeanddate.com/worldclock/converter.html?iso=20181211T060000&amp;p1=165&amp;p2=215&amp;p3=224&amp;p4=240
       
       

    • By DavinCreed
      As I like to say with a deep sadness in my soul, I've been failing at game dev for about three decades. I've been having fun, but I'm ultimately disappointed with my progress. So I've once again changed my goals and strategy and over engineered it. Which brings me to my current project.
      My new goal is to get better through repetition, but using a strategy for that repetition to make my skill development more efficient. So far, I've completed some clones of the first levels of two games (Ninja Gaiden and Super Mario Bros. for the NES), and am starting out on making the first level of Bionic Commando (also for the NES). I'm redoing the graphics in half the res of the originals for now.


      So far, this strategy seems to have taught me more in the few months I've been doing it, than the five years it took me to complete my last game. The difference I suppose is that I'm not going to attempt to release most of these games. I might consider polishing and releasing the ones that aren't clones. This big learning project looks like it will take me a few years, in the meantime I'll probably start other projects while still working through it but this is going to be my primary project for a long while. And something that I think I should have done in the first place so many years ago.
      I'd like to share my progress from time to time and hopefully have some discussions.
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!