d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Make Me A Better Programmer - From Step 1
Prev1353637383956Next
Add Reply New Topic New Poll
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
May 5 2014 02:08am
and with that, I have finished my last operating systems assignment. (I made a REALLY SHITTY file system - MY FLAT DIRECTORY STRUCTURE NEEDS NO LOAD BALANCING!)

holy shit what a class that was.

I will be impressed if I retain 10% of what I learned.


edit:


I would like to mention something -

If you read my very first post, I said I would post code for my assignments. I feel like I haven't been doing that lately.

The thing is, my OS assignments were all done using a shitty software emulator called OSP, written in C on a UNI machine w/ an old ass C compiler. The code looks nasty, its hard to understand and TBH I don't really want it to be seen :p


INSTEAD, I can post my code for my networking assignment. I will put it up here next.

This post was edited by Eep on May 5 2014 02:15am
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
May 5 2014 02:22am
Client.cpp

Code
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <signal.h>
#include "helpers.h"


int main(int argc, char *argv[]) {

/* Trap sigint to close the socket if we have any issues */

signal(SIGINT, err_handler);

/* Data declarations */

int opt, sockfd, log_to_file, log_to_both;
sockfd = opt = log_to_file = log_to_both = 0;

/* Get command line options */

while ((opt = getopt (argc, argv, "vV")) != -1) {
switch(opt) {
case 'v':
log_to_file = 1;
break;
case 'V':
log_to_both = 1;
break;
default:
break;
}
}

/* Pass logging information */

logger_init(log_to_file, log_to_both);

/* Set up our socket descriptor */

sockfd = setup_connection();

/* Pass control to general flow handler */

general_flow_handler(sockfd);

return 0;
}


Helpers.h

Code
/* Custom struct which contains a full path - no uncompleted paths are sent by the server to us ever */

typedef struct fullpath {
char start[5];
char destination[5];
char city_one[5];
char city_two[5];
int totalTime;
int totalDistance;
int numCity;
} fullpath;

/* Forward function declarations */

void err_handler(int sig);

void logger(const char *message);

void logger_init(int file, int both);

int setup_connection();

void general_flow_handler(int sockfd);

void deserialize(int num, int sockfd, int choice);

void initiate_talk(int sockfd, int choice);

void neighbors(int sockfd, int choice);

void print_results(int choice, int num, fullpath paths[]);

void end_connection(int sockfd, int choice);


helpers.cpp

http://pastebin.com/raw.php?i=kcB92183

Had to use a pastebin for my source file

I have used C++ only a few times, so I am sure there are a lot of things I am doing wrong. Bear with me.

This post was edited by Eep on May 5 2014 02:30am
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
May 7 2014 04:59pm
I HAVE OFFICIALLY FINISHED OS GAHAHAHAHahahahahahahaahaaaaaaaaaaaaa
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
May 10 2014 04:59pm
Finished OS with an A....feels good

This post was edited by Eep on May 10 2014 04:59pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 10 2014 05:08pm
Quote (Eep @ May 10 2014 06:59pm)
Finished OS with an A....feels good


did you make less than A in other classes?
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
May 10 2014 05:22pm
Quote (carteblanche @ May 10 2014 06:08pm)
did you make less than A in other classes?


Got an A in networking, not sure on my software engineering class yet.
Member
Posts: 648
Joined: Jun 19 2007
Gold: 35.00
May 27 2014 11:28am
Having just finished reading this thread... (not sure what lead me to it, why or how long I've spent on it - it's honestly been SEVERAL hours :o ) and reading that doom 3 link you made (in page whatever... years ago...) then reading all the comments on it, coming back here to have someone say that it was just a big circle jerk and to read the reddit page about it. Reading the reddit page on it (and the comments) and being pretty much lost at what everyone was talking about by like page 10 onwards I gotta say...

Seeing you go from like week 1-2/month 2 and posting code looking for help not knowing a lot (asking what flow etc. was) to the last page where you talk about using it and encouraging someone else to jump into a programming language course was great.

I feel like I time traveled a bit (and looking at the dates on the first post compared to the last in a way I sort of did).

Congrats on how far you've gone - I might have to poke around a bit more on these forums 'cause this thread was a pretty good ****in' ride :)

Is there anything you would have done differently if you were to start again today "from scratch"? (aside from how the thread kind of turned angry in the first few pages)
Would you have swapped any classes for different ones? (+why?)

p.s.
I was thinking of learning a bit as a hobbyist (starting with Java or C/C++ : google has widely differing opinions on what to start with) either paying for a class from a local college on days that I have off from work or trying to find a free online tutorial (for just starting out is it worth paying a few hundred to learn from a professor or nowadays is there pretty good free online resources for beginners)?
edit: looking around further there are quite a few tutorials/free classes online for the various programming languages so maybe the question should be:
Would you recommend taking a class or two from a college as a hobbyist? Which classes would you recommend for the entry level programmer as giving the most bang-for-your-buck/interesting things learned (don't give a F*** about essays or even getting the credit for that matter but learning to think in different ways while you program little assignments etc. sounds interesting + some theory and knowledge of how things actually work - even if it's rarely used practically)

I had a 15 pack of beer when I started poking around the programmer's haven and spent the vast majority of my time on this thread. I now have 4 warm beers left sitting beside me so I guess it's time for bed, bookmarked this so I can see where you end up/if you continue documenting your career,
thanks for the read!

This post was edited by MnG on May 27 2014 11:43am
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
May 27 2014 02:10pm
Quote (MnG @ May 27 2014 12:28pm)
Having just finished reading this thread... (not sure what lead me to it, why or how long I've spent on it - it's honestly been SEVERAL hours  :o ) and reading that doom 3 link you made (in page whatever... years ago...) then reading all the comments on it, coming back here to have someone say that it was just a big circle jerk and to read the reddit page about it.  Reading the reddit page on it (and the comments) and being pretty much lost at what everyone was talking about by like page 10 onwards I gotta say...

Seeing you go from like week 1-2/month 2 and posting code looking for help not knowing a lot (asking what flow etc. was) to the last page where you talk about using it and encouraging someone else to jump into a programming language course was great.

I feel like I time traveled a bit (and looking at the dates on the first post compared to the last in a way I sort of did).

Congrats on how far you've gone - I might have to poke around a bit more on these forums 'cause this thread was a pretty good ****in' ride  :)

Is there anything you would have done differently if you were to start again today "from scratch"? (aside from how the thread kind of turned angry in the first few pages)
Would you have swapped any classes for different ones?  (+why?)

p.s.
I was thinking of learning a bit as a hobbyist (starting with Java or C/C++ : google has widely differing opinions on what to start with) either paying for a class from a local college on days that I have off from work  or trying to find a free online tutorial (for just starting out is it worth paying a few hundred to learn from a professor or nowadays is there pretty good free online resources for beginners)?
edit: looking around further there are quite a few tutorials/free classes online for the various programming languages so maybe the question should be:
Would you recommend taking a class or two from a college as a hobbyist?  Which classes would you recommend for the entry level programmer as giving the most bang-for-your-buck/interesting things learned (don't give a F*** about essays or even getting the credit for that matter but learning to think in different ways while you program little assignments etc. sounds interesting + some theory and knowledge of how things actually work - even if it's rarely used practically)

I had a 15 pack of beer when I started poking around the programmer's haven and spent the vast majority of my time on this thread.  I now have 4 warm beers left sitting beside me so I guess it's time for bed, bookmarked this so I can see where you end up/if you continue documenting your career,
thanks for the read!


haha thanks

If I had to start over but with some knowledge from now, I would probably fret less over not seeing the 'whole picture' like I did back then. I got REALLY upset when I didn't understand syntax or why some conventions were used and others weren't.

I would have taken criticism better. Yeah I had several angry posts, mostly because I didn't understand where the people posting were coming from. A lot of them are industry professionals or people who have been doing this for years. In CS, there are a lot of straight forward methods to accomplishing things, and one of your biggest resources a lot of times is just knowing your environment. You should be comfortable with debugging, basic logging and how to create a good google search query. I was under the impression that all these people simply memorized all this CS information and were trying (on purpose) to make themselves look BETTER by using terms I did not know. The truth is, they were actually using relatively common terms in the field to approach my problems in a logical manner, but I (who did not understand and felt like I was being talked down to) got mad instead.


I have a friend who is a hobbyist. To be completely honest, if it is a hobby, your best bet is to just

1: Figure out what you want to do
2: Find SPECIFIC examples of how to accomplish that, then modify them to your needs. (That is, start coding. Make mistakes, google your errors, and you will be surprised at how much you learn)
3: Research and find tutorials on those specific things.

This would be the fastest path to having a working application doing what you want I imagine.

As far as what classes I would suggest? If you are starting completely empty of CS knowledge, I would suggest 1-2 basic intro to programming courses. These will let you have some building blocks to toy with. They are usually extremely easy classes and cover basic data types, control structures and possibly some other stuff depending on the language/teacher.

With that knowledge you can make some pretty simple programs, text based applications to run inside of a shell.

Just remember to start small and learn from your mistakes.


Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jun 15 2014 12:30pm
Quote (Eep @ May 10 2014 06:59pm)
Finished OS with an A....feels good


Did you actually write an OS with full I/O and a bootloader and such, or only a theoretical OS. I tried making my own a while back but after I wrote the bootloader in assembler that setup the system to run compiled C code and wrote a simple hello world function I stopped. There were to many buys from the simple less than 90 line project to be dealt with lol.

I kinda want to attempt it again.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jun 15 2014 12:52pm
Quote (AbDuCt @ Jun 15 2014 01:30pm)
Did you actually write an OS with full I/O and a bootloader and such, or only a theoretical OS. I tried making my own a while back but after I wrote the bootloader in assembler that setup the system to run compiled C code and wrote a simple hello world function I stopped. There were to many buys from the simple less than 90 line project to be dealt with lol.

I kinda want to attempt it again.


I wish it was half as cool as that man. We studied all the theoretical shit, algorithms and all that.

The projects we did were 3 projects in C to learn about system calls, spawning children processes and semaphores. The next 4 were C projects implemented in an OS simulator called "OSP" (made in 1990 with zero updates since then). We essentially created like super high level code to mimic algorithms for context switching and process handling, resource management, memory management and implementing a simple file system. (A load balanced flat directory)

I personally enjoyed the memory management unit the most.

The only cool thing about the projects was that they were often open ended and he would score a bit higher to those who could squeeze more performance out of their algorithms (the simulator logged all statistics during a run so you could view it and compare it VS the professor's own run)

edit: The class was hard but not because of the # of lines of code - each project only took 300-400 or so. The problem was getting the simulator to work and understand it (it was POOOOOOORLY documented).

This post was edited by Eep on Jun 15 2014 12:57pm
Go Back To Programming & Development Topic List
Prev1353637383956Next
Add Reply New Topic New Poll