Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

I’m novice trying to claw my way up to intermediate in C#, just to have what I say in context.

I ran through that head first book (though I only had the second edition). It is pretty good. It explains the basics in clear ways that will have you ready to tackle more intermediate-to-advanced topics.

As for videos, I don’t know. I don’t even know about unity. Stay away from Thenewboston’s C# videos though. They weren’t bad, but they just ran through the topics without explaining too much about why you’d use what you were learning about. There were “projects” (like a captcha maker) within the video series that spanned several videos, but that’s the closest you get to really learning.

Reddit (I KNOW, shut up guys) has a /r/learnprogramming subreddit. You can search there for video tutorials on C#. I recommend that because I don’t know of any other place where you could be pointed to a good video series instead of trying to poke around on Youtube yourself. If you DO look for videos on your lonesome though, look for videos on a particular topic you don’t understand. If the person explains it good, hit up the rest of the series.

For more textual tutorials, I’d hit up codeproject or maybe dreamincode.

Try this for learning C#: https://www.youtube.com/playlist?list=PLfqPUB_iygqQ81zKz7duiQmMOEzrXojFH

Today I sent out 30+ job applications for junior programmer positions, had a few call backs, hopefully these will turn into interviews.

Does anyone have any advice for interviews?

One thing I’ve learnt from The Apprentice, is do your homework on the company and read what you’ve written on your CV lol.

Yeah, pretty much what you said would be my suggestions: if you put it on your resume be prepared to talk about it, every detail. As far as homework goes see what sort of technologies the company you are applying to uses so you can both answer questions they may ask about them and be prepared to ask questions about them.

I’m not really loving my job at this point. I don’t know if its the line of work itself (I don’t want this to be the case, I love technology and want to give back) or its this job specifically. Its my first programming job and I’m essentially isolated from the rest of the team, something I wanted to avoid. I kind of wanted a ‘mentor’ since I come from a small school with not the best CS department, I guess that’s a rare thing in the professional world though. I’m currently working on a project that is an upgrade for a customer from 6 years ago that exactly 1 person on my team has experience with and he is the manager and already being pulled in a million directions so getting a hold of him to ask questions is hard. When I do get him I’m nervous about asking questions because I’m self conscious about the questions being too basic or something I should already know. I know how stupid that is, rationally, but I can’t shake it.

I’ve applied to an AI shop near by and they responded positively to my resume. They asked for a phone interview next week and sent me a programming prompt. I’m not worried about the interview, I don’t understand it but I seem to be good in interviews, but designing and implementing a proper library is something that I don’t have experience doing so I’m not feeling awesome about how I’m going to do on that. I also have some questions for them but I don’t know how responsive they want to be with a prospective interviewee.

I’m going to include the details of the prompt. I’m not really looking for anything in specific I just need to get it out of my head and into the public. I hate letting things stew in my mind when I’m not sure if I’m on the right path or not. I would understand if no one wants to comment on it, seeing as its for an interview and getting help would sort of be cheating. I don’t know.

Details:

Spoiler

I need to implement a prototype blogging engine. It needs to have the following features:



- User can submit a post.
- User can retrieve a post.
- Add tags.
- Add comments to post.
- Retrieve posts by tag.
- Retrieve posts by author.
- Retrieve comments for post.


Being graded on



- Completeness of interface.
- OO design of solution.
- Use of best software practices.


So the question I have for them are: What exactly does a post need to consist of?

They don’t want me to use a database but I’m allowed to use an in-memory object to persist any data.
Thoughs so far



- My thought is to have an 'Engine' object that the user would implement in their code which would contain a HashMap which would contain all the posts.
- I think implementing an addPost(String body, String user, int i) method which would create a new Post object that will store the user and body values then put them in the HashMap. My problem with this is returning the key to the user so I can return the Post.
> This is one of the things I'm worried about. I don't know if its best practice to make the user supply the index in this situation. If I don't do this I don't know how to put the Post into a data structure and have the user know the index so they can retrieve it.
- If the user knows the index doing retrieves would be sort of trivial.
- I know I need to make a tagging system and I'm not sure if that is something I should keep in the Post object or have the tagging system be separate to cut back on memory storage.
> If its outside the Post object I think I could work out a way to look up posts based on tags faster than going through all of Posts in the Map and checking all of the tags inside the Post. But I haven't gotten this far since I'm still hung up on the first problem.


If anyone responds that would be awesome, even if its just to say that I’m really off-base and should scrub the interview next week.

You absolutely do not want the user passing in the index of the post, that is bad design. Have your function return an integer with the index of the post. This would be the “Post Number” and would also be the key to your HashMap. The HashMap should be stored inside of your code, not managed by the user.

Since your HashMap key is the post number, the user should know it.

Add a function for “NumPosts” that returns the current number of posts in the system; typically in a Blog system, it shows posts by date descending, so in that case the user will want to retrieve the newest post, in which case giving them a way to have the highest post number works.

Also in blogs/forums, theres always the ability to get a range of posts; the front page might always show the 10 newests posts, for instance. Having a getRange(int startPost, int postCount) function that takes in the firstPost Number and returns an array of the posts will be a good feature to have.

You may want to consider a DeletePost function too to go the extra mile

Overall it seems pretty straight forward; I am not really sure what you mean by having a user have an EngineObject though they manage. I think you have the right idea though; you’ll create a library, which is an Object that has all the necessary functions (addPost, retrivePost, etc), and then whoever is using your code will instantiate that object (BlogClass myBlog; etc) and use that class directly (myBlog.addPost, myBlog.retrievePost)

Make sure that to be complete, every function needed to actually create/manage a blog in included in your library class. They should not be addressing anything internal, only through the public functions you defined.

And make sure to have really clear documentation for each function. Have a blurb about what it does, comment for each parameter and what it represents, comment on the return type, comment on the expected input (i.e. if postNum is not a valid post, the post will return blank). Use proper formatting styles for comments (like here http://www.hongkiat.com/blog/source-code-comment-styling-tips/)



/** BlogClass::addPost
  * @desc Adds a string post to the memory of the BlogClass for later retrieval
  * @param string post - contains the html of the post to be stored. Cannot be blank.
  * @param string author - contains the name of the author writing the post. Cannot be blank.
  * @return int - contains the post number of the post that was added. returns -1 if the post or author was blank
*/        
int BlogClass::addPost(String post, String author)
{
 //magic goes here

}


as for styling, make sure your class is broken up into smaller chunks; make sure you have private functions that do the dirty lifting instead of copy/pasting the same code fragments everywhere. for example, addPost would probably call a separate function called “insert Post” that actually creates the object and stores it in memory, a HashMap or linked list or whatever you choose to use, and addPost is more of the interface with the library and can do the error checking (like making sure Post and Author aren’t blank) before calling insertPost. It makes it easier to do testing/unit tests on code like that.

You’re the man, Pimp. I think the thing I was most shaky on was where my responsibility as the author of the library ends and the user’s begins as far as the indexing thing goes. I thought of returning the index to the user but I wasn’t sure if I was supposed to make them keep track of it; I knew I didn’t like the idea of the user creating the index but I wasn’t sure if returning the number was any better. I knew I was going to have to document my functions really well and was planning on using the format you suggested but I hadn’t seen that sight before so again thanks for that.

Yeah that is where I was trying to go.

I greatly appreciate the input, PW.

No prob. I think returning the index is fine; the user isn’t required to keep track of it, but they can if they want.

I know its been dead in here but I have to bring it back with a question. How do you push back into a struct vector from user input in c++

String sInput;
Std::vector<string> Vec;
Cin >> sInput
Vec.push(sInput)

Something like this

here is an example of something I did. GetInt() and GetLine() are used instead of cin >> when getting userinput because my teacher gave us a built in program. I don’t know what to actually pushback because when I put an integer inside for people.push_back() I get a an error.


struct student
{
    string name;
    int idnum;
    int quizzes[5];
    char grade;
};

int main()
{

    vector <student> people ;
    cout << "How many students are there?";
    int numstudents = GetInt();
    people.push_back();
    for(int i = 0; i < people.size(); i++)
    {
        cout << "What is the students name? " << endl;
        people*.name = GetLine();
        cout << "What is their ID number? " << endl;
        people*.idnum = GetInt();

        cout << "What are their quiz scores?" << endl;
        for(int j = 0; j < 5; j++)
        {
            people*.quizzes[5] = GetInt();
        }
    }
}


It’s a vector of students, so you must pass an instance (technically a reference) of student to push_back() (though what actually is stored in the vector is a copy of what you pass). More like



vector<student> people;
for (int i = 0; i < numstudents; ++i)
{
    student person;
    person.name = GetLine();
    // etc...
    people.push_back(person);
}


You could do it more like you have it, but push_back() only adds one element to the vector, so you could do something like



for (int i = 0; i < numstudents; ++i)
{
    people.push_back(student());
}
// Then the loop you already have


However in this particular case you don’t even need to use push_back(). std::vector has a constructor that allows you to create it with a given number of elements already in it (either copies of what you provide or the default).



vector<student> people(numstudents);
// Use people* as in your original code


Still, I’d probably go with my first snippet as with that version people only ever contains “valid” students. (That is, students whose information has been supplied by the user.) With the other versions if something goes wrong you’re left with “default” students in the rest of the vector, which may or may not be so great.

OMG thank you. I was so stuck on this

a little diddy from Satoru Iwata about programming HALNOTE.

Need to post here and finish looking at the YT when I have a chance.

(Note: Left click the image and then right click to either open it in a new tab or download it to see it in a readable resolution!) So here’s a spontaneous Japanese magazine article scanlation I’d...

22k is a joke. I can’t believe they aren’t embarrassed throwing that number out there. I ask right away how much the job pays.

Looking at reviews for these two coding boot camps. Really trying to change jobs by next summer. Wouldn’t be applying to the camp until Jan’16, after fall quarter. Anyone here do them, or have experience working with people from one?

I still want to get my BA(which would not be in CS) but want to switch from my current job while doing so.

Sure you guys have seen this.

The programming languages it uses are Python and C++. The C++ mention really caught me by surprise.

So… I had to share this story, its so dumb.

I manage a plugin for some adobe software, it reads in a text file (that we generate in another app) then it processes the file, and creates all the objects inside adobe. Basically, takes their planning data and makes it real, so the artists can finalize it.

We have this bug, where not all the data would load. But it only happens on Mac, and only in CS6. Windows CS6, fine. Every other CS version, fine. Just Mac CS6.

I spent like multiple days just stepping through line by line (its like ~100k lines in the file we’re processing) trying to figure out WHY its failing .XCode is shitty for debugging, and since it only happens on mac, Im stuck using that. It cant even show me the values of the variables in the debugger properly. Ugh.

After like 3 days, I finally find out what is happening.

We have a function, called GetNextChar(). It gets the data stream (from a class Adobe provides and manages), reads in an int16 of data (2 bytes, since the data file is 2 byte encoding), then parses it to a character value and returns.

Theres a part where we look for <cr/> and replace it with a
, or something like that. So whenever we are reading the text, we use seek, to skip over those characters we don’t need. Works fine, convoluted maybe, but it works.

But I start noticing that the file stream was reporting “end of file” way too early.

I set up some debug data, namely where the stream pointer is at before and after the seek. Our seek goes back -10 bytes, so I set a check where if after the seek, our index is where we expect, and if its not, I just put a breakpoint.

So I run it again, and sure enough, I see this:

BeforeIndex: 500,000

After Index: 752,000

Da Fuck? Theres a bug in Adobes software (which they dont support and wont patch anymore), or also there might be something weird in the character data we are processing (the text file is run through customer scripts they’ve written themselves, so they might encode something weird? Dunno).

Basically, at some random point, the file stream will just fucking jump to the end. If I resave the file in my text editor, it doesn’t happen. But if I don’t, it does happen.

Well, fuck. How can I fix this, its a bug outside of my control…

then I get a crazy idea.



int beforeIndex = stream->GetPosition
Stream seek = stream->seek(seekVal*2, fromCurrentPosition);
int retval = stream->GetCharacter();
int afterIndex = stream->GetPosition
if(afterIndex != (beforeIndex + seekVal * 2)
{
  //we've hit the random bug.
  stream->seek(beforeIndex + (seekVal * 2), fromStartOfFile)
  retVal = stream->GetCharacter();
}

return retVal


Surely, if I seek to the same spot, its just going to error out again right?

Nope. Nope.

It works.

So basically, now in a hacky move, when I detect the seek goes wrong, we instead of using seekFromCurrentPosition instead do SeekFromStartOfFile, and get the correct character.

And now the file loads properly.

:coffee:

1 Like

So I was banging my head against the hypothetical brick wall the other day.

Trying to reduce power, so we’re making our payload use a lot less parts.
Note that I’m not experienced in setting up networks and this is heavy on changing that setup.

Drew a picture on the board of the new network setup, easy peasy, right? Ethernet coms with a sensor.
So this means, I need to update the managed switch in our command and control (C&C) unit to forward data from our sensor to our payload in a slightly different way. No problem.
I made the changes on our network config in linux to handle this. No problem.
Start up coms with the sensor but… nothing.
The switch says the port has power while the payload is on. Lights are on… why can’t I get data going?

Try things out… oops, made a network loop, crashed the linux computer in the payload. Don’t do that again.
Alright, take the payload out of the loop and just attempt to contact the sensor from our C&C… still unable.
Triple check my linux network configs, corroborating that yes, this should be working…
Load up the network switch docs, read and read and read. Tried out probably 12 different things to try to get it to work.

So finally, at my wits end after a few days, the VP of software comes over (he was gone for a few days). He was our linux guy who would set up networks in our system. Note that in the meantime, I had other people attempt to help me.

We double check vlan setup, it looks correct.
So I bring up the switch status page that shows connections status in real time, e.g. “green” means its plugged in on both ends.
So we just start unplugging ethernet cables in my payload until the green status goes out on the port of interest.

Oops, electrical had plugged the ethernet cables into the wrong places.

And here I was thinking I’d done something wrong with the switch or linux network config because that’s something I don’t know much about.

You guys might remember awhile back I posted about a game builder called Buildbox. After starting a new job I’ve found I’m completely burnt out doing apps at work then coming home to do more coding, the whole thing is nauseating to the point I’ve completely given up on my project for months now. I caught wind of some rumours that there would be a new version of Buildbox coming out which would be a significant improvement over the first version. So I’ve been toying with version1 for a few weeks getting to grips with the software ready for the v2 launch in Jan. Anyhoo they made an launch annoucement yesterday and I have to say I’m blown away at just how good this new version looks.

v1 was very restricted in the type of games you could make but v2 opens up the doors to make some very interesting platformers. You can do cutscenes, use multiple gametypes in the same game and come up with some innovative control mechanics.

I started a clicker game over the summer, using Unity. I got really busy and havent worked on it in months… I should start it up again.