• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Haly

One day I realized that sadness is just another word for not enough coffee.
My solution to question 5 isn't elegant, but it works and I was able to do it in under an hour.

EDIT: Oh, I'm off the mark for 4. Welp, not getting hired any time soon.
 

Chris R

Member
EDIT: Oh, I'm off the mark for 4. Welp, not getting hired any time soon.

4 is really simple when you think about it. Just sort the list and provide a custom compare method.

Make sure your solution works not only for the provided list but for a list that also includes numbers like 5, 50, 55, 56, ect.
 

survivor

Banned
Here's the link for anyone that's interested in those problems.

The guy writing comes off as an ass, but the problems are worth the read.

I read that yesterday. 1-3 I did them in my head since I was too lazy to write down the answers. The 4th one was quite challenging, but managed to eventually write some code that solves it.

The 5th problem I have no idea how to do it efficiently. The brute force way where you try every combination works fine under a second, but feels like there is a smart way to eliminate a lot of useless combinations.

I'm a bit unsure if I can solve them all in under an hour if it was a real interview. I feel like I would just be cracking under the pressure and struggle a lot.
 

Ledbetter

Member
My mind was blown the first time I saw debugging with watches and call stacks.

Yes, me too. I asked a question here a few weeks ago and someone (I think cpp_king) mentioned that using a debugger would help finding the problem.

Now, everytime when my program crashes I just set watches and see what is happening. Saves you the time of asking for help when you just can find what is going wrong with your code by yourself.

Here's the link for anyone that's interested in those problems.

The guy writing comes off as an ass, but the problems are worth the read.

I can come up with ideas to solve 1 to 4. Problem 5 is the hardest I think.
 
Dumb question. Is "date" an int data type? If so, how would that work in code? I mean how it's supposed to be written? Do I have to have 3 variable naming them "month", "day", and "year"? So I have to make a struct that holds them right? Would my parameter have three variables since I need three integers to make a date?
 

Chris R

Member
Dumb question. Is "date" an int data type? If so, how would that work in code? I mean how it's supposed to be written? Do I have to have 3 variable naming them "month", "day", and "year"? So I have to make a struct that holds them right? Would my parameter have three variables since I need three integers to make a date?
Date is a date, not an int. I can't think of a language that doesn't provide some data type for storing dates (and times)
 
Dumb question. Is "date" an int data type? If so, how would that work in code? I mean how it's supposed to be written? Do I have to have 3 variable naming them "month", "day", and "year"? So I have to make a struct that holds them right? Would my parameter have three variables since I need three integers to make a date?

To extend what rhfb was saying, check your language's references to see what kind of data is used to represent date types. Since I've seen you post C++ code, you should check out cppreference. They usually have very self contained examples for each function and I've found them the easiest C++ reference to read.
 

Ambitious

Member
Jesus Christ, I screwed up and deleted hours of work using git reset --hard. Thank god almost all of it was still visible in my shell, as I had used git diff a few times.
 

wolfmat

Confirmed Asshole
Jesus Christ, I screwed up and deleted hours of work using git reset --hard. Thank god almost all of it was still visible in my shell, as I had used git diff a few times.
You're an idiot. An idiot of the kind I've been before.
Been rescued by editors caching files before. That's some 'nononoyes' material right there.
 

Ambitious

Member
You're an idiot. An idiot of the kind I've been before.
Been rescued by editors caching files before. That's some 'nononoyes' material right there.

Lesson learned.
Fortunately, it took me not even ten minutes to restore everything (and finally commit it, for god's sake). So.. phew.
And I just realized that both Time Machine and IntelliJ made regular backups of my work. Completely forgot about that during my initial panic.


I've made a lot of progress with integrating OAuth. It's pretty much done, actually. All that's left is some more testing and a bit of UI refinement.

Speaking of which:

No you should persist the access token if you want to make further requests, and it'll eventually expire, at which point you're supposed to demand an access token again if you want to update user data. That's what the token is for (making requests in the name of the related user in the context of your app).

Of course you should persist the User ID -- this is what enables persistence. The access token will make it possible to login the user via Facebook, and log him in again once he's killed his cookies or whatever. Check the Graph API Explorer, for example, when you query /me: https://developers.facebook.com/tools/explorer/?method=GET&path=me&version=v2.3& -- you obtain an app-scoped user ID, which you can look up in your DB and it's good.

So social login works like this, in an abstract manner:
- Obtain the access token (login with POST-back or whatever)
- Query the token's owner at the platform
- Store ID and other stuff, but also the token if you want to make requests in his name without him being on the site
- User's browser gets his cookie, the cookie builds the session when viewing
- The cookie of course relates the viewer to your DB entry
- If applicable, refresh the token autonomously (not all platforms support this; Google+ does, for example)

So if the cookie is gone, you start the same sequence (demand access token), but as soon as the token owner is identified and you discover him in your database, you can build his environment as it was when he last manipulated data or whatever.

Thank you, this was really helpful. Really appreciate it.
 

survivor

Banned
So I have been reading about multibyte characters for C here and I'm trying to run their example using clang but I can't get it to work.

The sample code
Code:
#include <string.h>
#include <stdlib.h>
#include <locale.h>
#include <stdio.h>
 
// the number of characters in a multibyte string is the sum of mblen()'s
// note: the simpler approach is mbstowcs(NULL, str, sz)
size_t strlen_mb(const char* ptr)
{
    size_t result = 0;
    const char* end = ptr + strlen(ptr);
    mblen(NULL, 0); // reset the conversion state
    while(ptr < end) {
        int next = mblen(ptr, end - ptr);
        if(next == -1) {
           perror("strlen_mb");
           break;
        }
        ptr += next;
        ++result;
    }
    return result;
}
 
int main(void)
{
    setlocale(LC_ALL, "en_US.utf8");
    const char* str = "z\u00df\u6c34\U0001f34c";
    printf("The string %s consists of %zu bytes, but only %zu characters\n",
            str, strlen(str), strlen_mb(str));
}
The output should be
The string zß&#27700;&#127820; consists of 10 bytes, but only 4 characters
But I keep getting 10 characters instead. Anyone have any idea what could cause the difference? I do have clang 3.6 installed while on the website they use gcc or clang 3.5, but could that really be causing the issue?
 
4 is really simple when you think about it. Just sort the list and provide a custom compare method.

Make sure your solution works not only for the provided list but for a list that also includes numbers like 5, 50, 55, 56, ect.

Sure, but the custom compare part is not straightforward. I mean it's not super hard, but it's the kind of thing that most people will think they figured out when they missed a few edge cases. Like, for example, the guy who wrote the blog.
 

tokkun

Member
I saw an article "Five programming problems every Software Engineer should be able to solve in less than 1 hour". I wrote the following three functions for question 1: "Write three functions that compute the sum of the numbers in a given list using a for-loop, a while-loop, and recursion.".

How could I write these better, or optimize them better?

Code:
        public static int sumOfListRecursive(List<int> numbers)
        {
            if (numbers.Count == 0)
            {
                return 0;
            }
            else
            {
                int sum = 0;
                sum += numbers[0];
                numbers.RemoveAt(0);
                return sum + sumOfListRecursive(numbers);
            }
        }

When you are writing recursive functions, it can be better to make sure the recursive call is the last instruction executed in your function before it returns. This is called 'tail-recursion', and it can lead to higher performance and avoid problems like stack overflows because it allows the compiler to reuse the current stack frame rather than creating a new one.

Your code is not tail-recursive because after you make your recursive call, you then add it to the sum before returning. If you wanted to make it tail-recursive, you could do something like this.

Code:
        public static int sumOfList(List<int> numbers)
        {
            return sumOfListRecursive(numbers, 0);
        }

        public static int sumOfListRecursive(List<int> numbers, int sum)
        {
            if (numbers.Count == 0)
            {
                return sum;
            }
            else
            {
                sum += numbers[0];
                numbers.RemoveAt(0);
                return sumOfListRecursive(numbers, sum);
            }
        }

The other thing to point out is that using numbers.RemoveAt() requires you to destroy the list in order to sum it. If you wanted to keep it intact, you could pass the index of the current element instead.
 

Duji

Member
Hey guys.

So I'm nearing graduation with a few semesters left (Bachelor's in Comp Sci) and I'm... a bit worried about finding my first programming job.

I have a few school group projects under my belt, but nothing that I'd wanna show off to be honest. Simply put, what are some good ways to go about making myself more employable? Should I make my own personal programming project? If so, what? I feel like I'd have no idea what to make.

Can anyone offer me some advice please? Thanks.
 

Kalnos

Banned
Can anyone offer me some advice please? Thanks.

No one can tell you that, I'm afraid. Find a problem that needs solving or an app that you think could be improved and just go for it. Helps to be passionate about it e.g. I saw some guy on Reddit made a LFG tool for Chalice dungeons in Bloodborne. Easy idea that he's interested in because he was already playing that game. He will be able to explain clearly what he did and why and I think that sort of interest in projects will impress a company.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Another option would be a summer internship, although since we're already in May a lot of Comp Sci positions would be filled up already.

Still, it doesn't hurt to look around. Your college might also have career counselors who can help you find something.
 
Hello everyone, current bio student here. I want to eventually get into bioinformatics, so that requires me to start learning languages like sql and python. What are some good starter projects? I've been to the reddit for beginning projects and seen in the "learning python the hard way" that it culminates in the creation of a website but I was hoping to get some perspective from people more steeped in the field as to what might be a good place to start with python for example.
 

Zapages

Member
I have simple AWK question in Linux. I have been following some examples and figured out on how to do the following with a Fasta file:

A fasta file looks like this:

>Sequence_name
ATCGCA
>Sequence_name
ATCAGA


Add characters at the end of the fasta header with Contig numbers 1 to n:
Code:
awk '/^>/{$0=$0"_Contig_"(++i)}1' input_file.fasta > output_file.fasta


>Sequence_name
ATCGCA
>Sequence_name
ATCAGA

Changed to:

>Sequence_name_Contig_1
ATCGCA
>Sequence_name_Contig_1
ATCAGA

Replace the Fasta header with Contig numbers 1 to n:
Code:
awk '/^>/{print ">Contig_" ++i; next}{print} input_file.fasta > output_file.fasta

Likewise in:

>Contig_1
ATCGCA
>Contig_2
ATCAGA

But how do adjust the code to so that the Contig_n_Sequence_name:


>Contig_1_Sequence_name
ATCGCA
>Contig_2_Sequence_name
ATCAGA

Any advice on how to go about this?

Many thanks.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Hello everyone, current bio student here. I want to eventually get into bioinformatics, so that requires me to start learning languages like sql and python. What are some good starter projects? I've been to the reddit for beginning projects and seen in the "learning python the hard way" that it culminates in the creation of a website but I was hoping to get some perspective from people more steeped in the field as to what might be a good place to start with python for example.

Learn Python the Hard Way is a great place to start. I would begin there.
 

Ke0

Member
Hello everyone, current bio student here. I want to eventually get into bioinformatics, so that requires me to start learning languages like sql and python. What are some good starter projects? I've been to the reddit for beginning projects and seen in the "learning python the hard way" that it culminates in the creation of a website but I was hoping to get some perspective from people more steeped in the field as to what might be a good place to start with python for example.

LPTHW is still a great resource regardless of what the end result it. The point of LPTHW isn't the end result, it's the journey and everything you pick up by the time you reach the end. Once you learn the ins and outs of python you can bend it to your will to work with anything to include your bioinformatics.

Python for the web and python for bioinformatics is the same python for applications is the same python Bill Jol used to create his personal comic viewing program on Windows.

LPTHW is teaching how to code and understand the python language, what you do with it after you've learned python is up to you.

Either way, Python is an awesome language, have fun learning!
 

Holundrian

Unconfirmed Member
So during a project assignment I got the chance to play around with one of those micro controllers(in my case the atmega2561) and wrote a small game for it(purely in C).
During classes we talked a bit about assembly in that context but we didn't really delved into working with it. So now I know a few things like what "ldi" means but I don't really have a grasp about the overall logic behind it all but I'm still kind of interested in learning about it.

I've heard that to really develop and understanding you need to know about von neumann architecture(which is something I think we're tackling next semester).
In any case I just wanted to ask about any useful materials I could look at to try to work myself into assembly.

I assume a good way to learn is trying to rewrite/optimize code?
 

0xCA2

Member
Tutoring what and at what level? Does the person/people that you plan to tutor earn an income?
First class in CS sequence. I don't know if the student earns an income but their parent contacted me.

I replied telling them the rate was negotiable and asking then give me more info about their circumstances and needs. I want to start at 25
 
First class in CS sequence. I don't know if the student earns an income but their parent contacted me.

I replied telling them the rate was negotiable and asking then give me more info about their circumstances and needs. I want to start at 25

Make sure to factor in your cost (incl. time) of travel.
 
First class in CS sequence. I don't know if the student earns an income but their parent contacted me.

I replied telling them the rate was negotiable and asking then give me more info about their circumstances and needs. I want to start at 25

Depends on where you live. Many professional tutoring service charge up to 50. I would start less than that since you're not a professional tutoring service. Your idea of $25 seems reasonable, you might try for $30 if youre feeling a little ballsy
 

Ledbetter

Member
I'm going into the 4th semester of Computer Engineering. My university offers two computer majors, the one I'm studying now and the other one I don't know exactly how to say it in English, but in Spanish is Ingeniería Informática.

We share a lot of classes the first two years (Data Structures, Algorithms, Calculus, DB, etc.). Later on, CE focuses on classes like Computer Architecture, Computer Organization, NOS, mostly hardware stuff I guess.

The other engineering (I think is also called Computer Engineering in the US haha) focuses on the handle of data (Mining, Warehouse), AI, Network and Server Administration. The thing is I can switch to this major next semester without losing any progress, because I find myself a little bit more interested with these classes. But one of the reasons I think that is because I don't have a clear idea about what can be learned on the "hardware" classes and if this knowledge is more looked upon in the industry.

So, what do you think? Which of these two do you find more interesting and relevant to learn?
 

Mr.Mike

Member
I'm going into the 4th semester of Computer Engineering. My university offers two computer majors, the one I'm studying now and the other one I don't know exactly how to say it in English, but in Spanish is Ingeniería Informática.

We share a lot of classes the first two years (Data Structures, Algorithms, Calculus, DB, etc.). Later on, CE focuses on classes like Computer Architecture, Computer Organization, NOS, mostly hardware stuff I guess.

The other engineering (I think is also called Computer Engineering in the US haha) focuses on the handle of data (Mining, Warehouse), AI, Network and Server Administration. The thing is I can switch to this major next semester without losing any progress, because I find myself a little bit more interested with these classes. But one of the reasons I think that is because I don't have a clear idea about what can be learned on the "hardware" classes and if this knowledge is more looked upon in the industry.

So, what do you think? Which of these two do you find more interesting and relevant to learn?

I'm guessing the second degree you refer to is what we would call Computer Science or Software Engineering, as opposed to Computer Engineering which does a lot more with the hardware (and is in fact, in many schools, taught as a specialization of Electrical Engineering).

I can't really speak to which one might be "better", but I don't think either is a bad choice. Figure out what you're more interested in learning and then doing later on and make your choice based on that I guess.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I'm going into the 4th semester of Computer Engineering. My university offers two computer majors, the one I'm studying now and the other one I don't know exactly how to say it in English, but in Spanish is Ingeniería Informática.

We share a lot of classes the first two years (Data Structures, Algorithms, Calculus, DB, etc.). Later on, CE focuses on classes like Computer Architecture, Computer Organization, NOS, mostly hardware stuff I guess.

The other engineering (I think is also called Computer Engineering in the US haha) focuses on the handle of data (Mining, Warehouse), AI, Network and Server Administration. The thing is I can switch to this major next semester without losing any progress, because I find myself a little bit more interested with these classes. But one of the reasons I think that is because I don't have a clear idea about what can be learned on the "hardware" classes and if this knowledge is more looked upon in the industry.

So, what do you think? Which of these two do you find more interesting and relevant to learn?

It's entirely up to you and what you enjoy.

Do you like low level architecture and programming, or higher level application development?
 

Slavik81

Member
Not that shocking really, even "experts" can get simple things wrong from time to time. This goes doubly for programming.
It's a little shocking to me. I don't post something as an answer unless I'm sure. And, you're encouraged to delete your answer if you're wrong. My suspicion is that it's strategic. That is, that you tend to get more rep by quickly guessing than you do by waiting to make informed posts.

Also, apparently you can get a badge for linking people to answers. Didn't know that. All you lurkers made me an Announcer.
 
I have simple AWK question in Linux.

Not 100% sure on what you're looking for but if you have

Code:
>Sequence_name
ATCGCA
>Sequence_name
ATCAGA

you can use the substr() function
Code:
awk '/^>/{print ">Contig_" ++i "_"substr($0, 2); next}{print}'

to get

Code:
>Contig_1_Sequence_name
ATCGCA
>Contig_2_Sequence_name
ATCAGA
 
I was shown a program at work last Thursday that I'm required to update. Never seen the code or even used the program before that, and it hasn't been updated in over a year.

I was able to get a bit accomplished yesterday and today, but the constant "magic numbers", absolutely no comments, and hard to read code in general is giving me headaches.

Anyone else ever have this experience? Any tips for me? :p
 
I was shown a program at work last Thursday that I'm required to update. Never seen the code or even used the program before that, and it hasn't been updated in over a year.

I was able to get a bit accomplished yesterday and today, but the constant "magic numbers", absolutely no comments, and hard to read code in general is giving me headaches.

Anyone else ever have this experience? Any tips for me? :p

Try to write a bunch of tests for it. Then it's easy to verify that the changes you're making are sound, and it also helps you to understand the code at the same time
 
In reading through this Effective Modern C++ book, a lot (and I mean a lot) of new features use templates. Do y'all have any advice for learning/working with templates in general? I'm pretty weak in that area.
 

tokkun

Member
In reading through this Effective Modern C++ book, a lot (and I mean a lot) of new features use templates. Do y'all have any advice for learning/working with templates in general? I'm pretty weak in that area.

My general advice would be to go ahead and use the STL all you want, but try to avoid writing your own templated code as much as possible. Prefer using overloading or polymorphism instead of writing template code when you can.
 
My general advice would be to go ahead and use the STL all you want, but try to avoid writing your own templated code as much as possible. Prefer using overloading or polymorphism instead of writing template code when you can.
For compile time reasons? Hidden bugs? Too much time to implement with too little gains?
 
What's the formula for getting base salary and current annual salary? Or there aren't one? I need to get the user's input for base salary and current annual salary, and return them.
 
Top Bottom