• 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

JesseZao

Member
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.

I think it's in the prefab Answers class. You just pass in the book isdn and the exercise number and it outputs the correct method(s) to use in a string array.

======

On topic: I found some fun websites to practice my math/logic/programming skills.

Codingbat.com
Projecteuler.net

The latter has some crazy difficult problems near the end.
 
I think it's in the prefab Answers class. You just pass in the book isdn and the exercise number and it outputs the correct method(s) to use in a string array.

On topic: I found some fun websites to practice my math/logic/programming skills.

Codingbat.com
Projecteuler.net

The latter has some crazy difficult problems near the end.

Do I have to sign up for that website or no?
 

JesseZao

Member
Do I have to sign up for that website or no?

Edit: I was being snarky. Your post had no context, was a random part of a homework question, and I couldn't tell if you were serious.

In case you were wondering about the sites I posted.

codingbat - only requires a login if you want to save your progress

projecteuler - does actually require a login to do the problems, but you can view the problems here first https://projecteuler.net/archives
 
Edit: I was being snarky. Your post had no context, was a random part of a homework question, and I couldn't tell if you were serious.

In case you were wondering about the sites I posted.

codingbat - only requires a login if you want to save your progress

projecteuler - does actually require a login to do the problems, but you can view the problems here first https://projecteuler.net/archives

I wasn't joking. The question I was asking relates to the homework problem. If you want, I could PM you the question so you'll have a clear idea.
 

poweld

Member
I wasn't joking. The question I was asking relates to the homework problem. If you want, I could PM you the question so you'll have a clear idea.

I think you need to use the modulo operator on the base salary to to find the annual salary, unless if we are taking into account compound interest, in which case you may want to consider the XOR operator. I presume you're using booleans in your solution?
 

JesseZao

Member
I think you need to use the modulo operator on the base salary to to find the annual salary, unless if we are taking into account compound interest, in which case you may want to consider the XOR operator. I presume you're using booleans in your solution?

This rabbit hole could go deep.
 
For compile time reasons? Hidden bugs? Too much time to implement with too little gains?

Writing generic code is not easy to begin with (unless the language makes it really easy for you, e.g. Haskell) and C++'s implementation of generic code is one of the hardest to use correctly (Lovecraftian compiler error messages). The benefit is also generally pretty small, unless you're either writing a library for other people to use or do actually need the code to be generic.
 
Hey I guess I need some help thinking through the creation of a shopping cart/check out system in .Net using C#.

Well, not so much the concept of adding items, removing them, calculating, etc. More along the lines of what happens when you go to checkout, and two people are checking out at the same time for the same item but there is only one in stock. A customer should not be allow to check out if items are out of stock.

Has anyone had experience thinking about this type of thing?

One idea I have is:

-Since I'll be hosting in azure, each product can have a container, and once the customer checks out, put a lock on the containers so no other cart can grab them, try to process payment, decrease qty, unlock. I feel like this can make the checkout process slow tho.

Does anyone else have any ideas or tips?
 
I think you need to use the modulo operator on the base salary to to find the annual salary, unless if we are taking into account compound interest, in which case you may want to consider the XOR operator. I presume you're using booleans in your solution?

It's hard for me to explain because this homework is about polymorphism. My instructor gave us a demo she showed in class where we need to use it as a base class for my homework. I'm making a class called foo_employee where it's considered as a derived class. This class will include data members such as employment_date, current_annual_salary, base_salary, and a dynamic array which keeps track of current_annual_salary increase rate sine year of employment. Then I set up these member functions which are default constructor, destructor, copy constructor, assignment operator, getters and setters for each data members I've mentioned. Overloaded operator where I have to print out employee's information. Then there's this output function where my instructor declared it in the base class and I have to redefine it which I'm unsure what I'm supposed to do for that part. The homework is due tomorrow, and I have yet to scratch the surface for this problem
 

JesseZao

Member
It's hard for me to explain because this homework is about polymorphism. My instructor gave us a demo she showed in class where we need to use it as a base class for my homework. I'm making a class called foo_employee where it's considered as a derived class. This class will include data members such as employment_date, current_annual_salary, base_salary, and a dynamic array which keeps track of current_annual_salary increase rate sine year of employment. Then I set up these member functions which are default constructor, destructor, copy constructor, assignment operator, getters and setters for each data members I've mentioned. Overloaded operator where I have to print out employee's information. Then there's this output function where my instructor declared it in the base class and I have to redefine it which I'm unsure what I'm supposed to do for that part. The homework is due tomorrow, and I have yet to scratch the surface for this problem

Honestly, go over your lecture notes for the unit or re-read the assigned chapter. You need to learn the concepts of programming if you want to succeed. Getting shortcuts does you no favors.

If it's a simple question that stack overflow could answer, that's fine, but you shouldn't ask other people to do your homework. It only hurts you in the long run.
 
Writing generic code is not easy to begin with (unless the language makes it really easy for you, e.g. Haskell) and C++'s implementation of generic code is one of the hardest to use correctly (Lovecraftian compiler error messages). The benefit is also generally pretty small, unless you're either writing a library for other people to use or do actually need the code to be generic.
Thanks for explaining. Guess I'll hold off on that until needed.
 

NotBacon

Member
It's hard for me to explain because this homework is about polymorphism. My instructor gave us a demo she showed in class where we need to use it as a base class for my homework. I'm making a class called foo_employee where it's considered as a derived class. This class will include data members such as employment_date, current_annual_salary, base_salary, and a dynamic array which keeps track of current_annual_salary increase rate sine year of employment. Then I set up these member functions which are default constructor, destructor, copy constructor, assignment operator, getters and setters for each data members I've mentioned. Overloaded operator where I have to print out employee's information. Then there's this output function where my instructor declared it in the base class and I have to redefine it which I'm unsure what I'm supposed to do for that part. The homework is due tomorrow, and I have yet to scratch the surface for this problem

Read up on virtual functions and function overriding.
 
Dumb question but...whats the difference between a programmer analyst, software developer and a software engineer?

^In my experience, pomposity.

In addition to that, it could be organization specific. For example, my company lumps people into certain titles based on experience and responsibilities.

People with less experience get lumped into roles with "Programmer Analyst" titles. People with more get lumped into roles with "Engineer" titles. Within each group, there's still further breakdown based on experience level (fresh out of college, 2 years, etc., on one side, 5 years, 10 years, etc., on the other).

At least at my company, it gives you a good idea for your career (and compensation!) progression, assuming you're absorbing information and gaining knowledge, not just operating in a brain-dead manner and never stretching your boundaries.
 

MarkusRJR

Member
So I'm taking Comp Science at my local university in a few months. Will a low end computer be usable for school or will I need something a little more high end?
 

Jokab

Member
So I'm taking Comp Science at my local university in a few months. Will a low end computer be usable for school or will I need something a little more high end?

I know a few people in my class who have Notebook laptops that are like six or seven years old. I would never want to do programming on any of them because of how much IDEs hog memory, but they seem to do the job. I bought a mid-range ASUS ultrabook when I started three years ago and I'm still using it. You don't need high-end, but I would personally go crazy trying to program on a low-end one.
 
So I'm taking Comp Science at my local university in a few months. Will a low end computer be usable for school or will I need something a little more high end?

Like Jokab said, something midrange will do. Using Visual Studio 2013 on my low end laptop is a nightmare. A low end laptop definitely works, but you'll probably be annoyed by how slow it makes things.

I also notice that when I'm programming, that is usually the time when I have the most tabs going in Chrome lol. Might be something to consider if you think you'll need to multitask.
 

MarkusRJR

Member
I know a few people in my class who have Notebook laptops that are like six or seven years old. I would never want to do programming on any of them because of how much IDEs hog memory, but they seem to do the job. I bought a mid-range ASUS ultrabook when I started three years ago and I'm still using it. You don't need high-end, but I would personally go crazy trying to program on a low-end one.

Like Jokab said, something midrange will do. Using Visual Studio 2013 on my low end laptop is a nightmare. A low end laptop definitely works, but you'll probably be annoyed by how slow it makes things.

I also notice that when I'm programming, that is usually the time when I have the most tabs going in Chrome lol. Might be something to consider if you think you'll need to multitask.
Hmmm... okay. So doable but not advisable.

I was thinking of getting an all-in-one for my room (have no room for a tower) and this one is super cheap. Is it good enough or should I splurge and get this one?
 

NotBacon

Member
Hmmm... okay. So doable but not advisable.

I was thinking of getting an all-in-one for my room (have no room for a tower) and this one is super cheap. Is it good enough or should I splurge and get this one?

Mmmmmm I don't know how others feel about it, but I've always recommended against all-in-ones.

My advice is to get a notebook with an ssd and a bunch of ram. I would say those are the most important components by far.
 

Water

Member
So I'm taking Comp Science at my local university in a few months. Will a low end computer be usable for school or will I need something a little more high end?

95% of things that might come up in computer science can be done perfectly well with a weak laptop. Universities have computer labs you can use for the other 5%, if you actually happen to encounter courses in that category. You might later choose to specialize in something that mostly falls into the 5%, but by that point you'll have a much better idea of what you actually need.

If you want to spend money, spend it on a good laptop. Priorities are good screen, good keyboard, good battery life, light and compact enough that you have no desire to leave it at home, and of course a SSD. CPU performance almost doesn't matter in vast majority of uses. Laptops where all the aforementioned things are in order will never have a weak, netbook-caliber CPU anyway. GPU matters even less often.

I have done nearly everything in my computer science studies with a Macbook Air. That includes planning and teaching my own course on Unity game programming. Only thing where I have needed to use other machines was studying, and later teaching, computer graphics. For that, I needed A) a Windows machine, B) a more full-featured GPU than Intel integrated. GPU performance still didn't matter for that purpose, a $60 Nvidia desktop part based on 3-year old tech was more than enough.
 

Slavik81

Member
So I'm taking Comp Science at my local university in a few months. Will a low end computer be usable for school or will I need something a little more high end?
I used a 3-year-old netbook running Lubuntu for several months, and it was perfectly fine. You can do just about everything with a basic text editor, if you know what you're doing. For later sections of my 3rd-year Computer Graphics course, the graphics card was too old and Intel's drivers were too bare-bones, but I could have used the computer lab if I needed to.

That said, I later bought a beastly MacBook Pro and I'm quite happy using the extra power. It cost a small fortune, but if you have money to spare it's nice.

Dumb question but...whats the difference between a programmer analyst, software developer and a software engineer?
They could potentially all be different names for the same thing. Though, depending on where you live, engineer may be a protected title.

In Canada for instance, you cannot call yourself an engineer without having an engineering degree (or passing equivalent exams), passing a law and ethics exam, working for 4 years under the supervision of another engineer, and registering with a professional association.
 

JeTmAn81

Member
I used a 3-year-old netbook running Lubuntu for several months, and it was perfectly fine. You can do just about everything with a basic text editor, if you know what you're doing. For later sections of my 3rd-year Computer Graphics course, the graphics card was too old and Intel's drivers were too bare-bones, but I could have used the computer lab if I needed to.

That said, I later bought a beastly MacBook Pro and I'm quite happy using the extra power. It cost a small fortune, but if you have money to spare it's nice.


They could potentially all be different names for the same thing. Though, depending on where you live, engineer may be a protected title.

In Canada for instance, you cannot call yourself an engineer without having an engineering degree (or passing equivalent exams), passing a law and ethics exam, working for 4 years under the supervision of another engineer, and registering with a professional association.

That's pretty cool. It does peeve me when people refer to themselves as engineers but don't do the kind of work that you would ever think of as "engineering".
 

OceanBlue

Member
Lol I tried to get by on a cheap netbook in college, but when I had to do things like program to a CPLD or compile Minix, it would take me way too long. I would take hour-long quizzes that I had to finish 30 minutes early just so I had enough time to compile a Quartus project and get it on my microprocessor board. When doing operating systems projects, I just remote desktop'ed to my computer at home because it would take me two hours to compile Minix on my netbook. Looking back on it, it's kinda funny. :V
 

0xCA2

Member
I'm pretty sure I just flunked my OOP2 (Data structures) final. I think I can pass the course with a C because I had an 85 before it, but still. I just freeze up on these programming questions like nothing else, and losing confidence in one problem makes me forget everything.

The one question I had was:
- sumPaths(BST, target)
- Returns true if any of the paths of BST match target. No auxiliary methods, no collections, recursion only.
- I'm just now realizing that you're supposed to traverse as regular, decrement target by the value at the node, and at the return if target is == 0 when you reach a leaf node. After hours of thought this solution just came out of nowhere.

These tests sometimes require you to do some slick shit on the fly, but I always end up too flustered to do it. Guess I just have to get better at it. Though if I end up having to retake the course I'll be so freaking devasted.
 

JeTmAn81

Member
I'm pretty sure I just flunked my OOP2 (Data structures) final. I think I can pass the course with a C because I had an 85 before it, but still. I just freeze up on these programming questions like nothing else, and losing confidence in one problem makes me forget everything.

The one question I had was:
- sumPaths(BST, target)
- Returns true if any of the paths of BST match target. No auxiliary methods, no collections, recursion only.
- I'm just now realizing that you're supposed to traverse as regular, decrement target by the value at the node, and at the return if target is == 0 when you reach a leaf node. After hours of thought this solution just came out of nowhere.

These tests sometimes require you to do some slick shit on the fly, but I always end up too flustered to do it. Guess I just have to get better at it. Though if I end up having to retake the course I'll be so freaking devasted.

Is your target a single node or something else? If the former, isn't that just a normal search through the BST?
 

0xCA2

Member
Is your target a single node or something else? If the former, isn't that just a normal search through the BST?

I should've made it more clear; its an integer that isn't in the tree. This isn't to search for the target, if that's what you were asking. You're supposed to "sum up" all the nodes in a path up to a leaf and then return true if any of the paths are equal to the target.
Code:
   4
 1    6
0  2

Lets say the target is 10. then this would return true.

I spend the whole test trying to figure out how to add up when you'd really get the answer only by subtracting (specifically recursively decrementing the target by the value at the node).

Edit; Also, yeah it it could've used any form of traversal (inorder, preorder, etc) if that was what you meant.
 
Man, even the basics of recursion are kinda breaking my brain.

For example, in Racket:

Code:
(define (cheapest los)
      (if (cheaper? (first los) (cheapest (rest los)))
             (first los)
             (cheapest (rest los)))]))

That you can call a function on the first element of a list and have the second argument of the function be a different function that uses the rest of the list is just making me go "what is this wizardry?!?"
 

JesseZao

Member
Man, even the basics of recursion are kinda breaking my brain.

For example, in Racket:

Code:
(define (cheapest los)
      (if (cheaper? (first los) (cheapest (rest los)))
             (first los)
             (cheapest (rest los)))]))

That you can call a function on the first element of a list and have the second argument of the function be a different function that uses the rest of the list is just making me go "what is this wizardry?!?"

Praise the Stack!
 

mltplkxr

Member
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

All you need to know:
http://www.amazon.com/dp/0131177052/?tag=neogaf0e-20

Personally, when I don't understand a piece of code, I document it. For OO: sequence diagrams, class diagrams, etc. No need to be fancy, just enough detail to understand what I need.

Branch by Abstraction will help too: http://martinfowler.com/bliki/BranchByAbstraction.html
 

mltplkxr

Member
In addition to that, it could be organization specific. For example, my company lumps people into certain titles based on experience and responsibilities.

People with less experience get lumped into roles with "Programmer Analyst" titles. People with more get lumped into roles with "Engineer" titles. Within each group, there's still further breakdown based on experience level (fresh out of college, 2 years, etc., on one side, 5 years, 10 years, etc., on the other).

At least at my company, it gives you a good idea for your career (and compensation!) progression, assuming you're absorbing information and gaining knowledge, not just operating in a brain-dead manner and never stretching your boundaries.

Yeah, it's mostly HR speak. I always refer to my job in a very general term (that I don't exists in English). If it's not enough, then I give 2 or 3 of the hats I wear in a given week.

There is a real difference between scientist and engineer though. Steve McConnell made me realize this and I adhere to his distinction ever since I read it. He writes about here: Software Engineering, Not Computer Science. I think everyone would be better off if the distinction between computer science and software engineering was clear to everyone.

When I read about computer science majors that can't code, I now think "Of course!". The curriculum (well the program I did) is based on the mathematical and scientific foundations of computer programming, not on software development. Math and programming classes, basically.

On the other hand, software development is about breaking down requirements, writing tests, measuring performance and quality, etc. None of which was really thought in school.
 
Went back into battle with clang today/tonight, but finally hit a brick wall.

Apparently there's no support in the c++abi for __cxa_thread_atexit, which means you cannot link when you've declared a (static?) thread local variable.

Which means I can't use -stdlib=libc++ (instead having to use gcc's), which means std::regex doesn't work with clang, because clang shits the bed when you use the default glibc and std::regex.

t('.'t)
 

Ambitious

Member
I've got a weird issue with Hibernate.

Code:
lectureWrapper = em.find(LectureWrapper.class, dto.getId());

lectureWrapper = em.createQuery("from LectureWrapper where id=:id").setParameter("id", dto.getId()).getSingleResult();

"em" is the EntityManager object.
The second line returns the LectureWrapper with the given ID. The first line does not; it returns null instead. I don't get it.

The obvious assumption is that the LectureWrapper class is not correctly annotated. But it is! The class is annotated with @Entity, and the getId() method is annotated with @Id and @GeneratedValue.
In order to verify this, I had Hibernate print the queries:

Code:
Hibernate: select lecturewra0_.id as id0_0_ from LectureWrapper lecturewra0_ where lecturewra0_.id=?

Hibernate: select lecturewra0_.id as id0_   from LectureWrapper lecturewra0_ where lecturewra0_.id=?

Apart from the different alias, they're the same (I've removed the other fields for brevity). I have no idea what's going on here.

According to a StackOverflow post, this might happen is there's a row where the ID is null. But that's definitely not the case.
 

mltplkxr

Member
You could setup p6spy to print out the queries. In your example id=? . With p6spy, you'll know what's passed with the query, ex id=6. That might help find the issue.
 

Ambitious

Member
You could setup p6spy to print out the queries. In your example id=? . With p6spy, you'll know what's passed with the query, ex id=6. That might help find the issue.

For the time being, I left the createQuery and commented the find() call out so I could focus on other stuff. But after some unrelated changes, even this doesn't work anymore.

Something is seriously wrong with my code.
The test code is persisting two entities, and I've added debug output to read the whole LectureWrapper table directly after the call to persist. After persisting entity 1, the table contains only entity 1. After persisting entity 2, the table contains.. only entity 2? What?

No idea how I could proceed from here. I'm calling persist and then flush afterwards. I can see the Hibernate INSERT in the output. I'm printing the entities after the persist call, and they do have IDs assigned by Hibernate. It's the same EntityManager in both calls. Sounds like everything should work as expected.
I feel like the problem could be related to transactions. The code is multi-threaded (I have already verified that each entity is persisted by a different thread), and the project uses JTA, which I don't have any experience with.

What I find really weird is that I've compared my project with a co-student's (it's an assignment for a lecture), and his code is basically the same. No special transaction logic or anything.

Anyway, my next step is to create a minimal working example.
 

Rust is great, I've posted about it before, I think it's one of the most interesting languages around right now and it very much aligns with what I like in a programming language. The big feature that is advertised for Rust is the safety against most memory errors without reliance on a GC, but for me the most interesting part is C++-like performance without the warts of C++ and a lot of modern language features (algebraic data types, great support for generics, value types as default, pattern matching, lazy, composable iterators for stream processing). The compiler is rather strict (e.g. no implicit casting from integers to floating points) and can sometimes be annoying, especially when it comes to lifetime issues, but it almost always points to an actual error in your code that would at some point (or always) fail during runtime. The compiler error messages have also gotten progressively better and are very useful now.
 
I think rust will have a very positive impact, even if the most it ever achieves is "niche language".

For example, the idea of explicitly marked "unsafe" sections of code being the only places you allow pointer manipulation (etc) is an idea that could and should be adopted by C++. (I imagine a "#pragma unsafe" define, and a compiler flag that freaks the eff out if the pragma isn't present in the compilation unit where pointer manipulation is happening)

And the fact it's finally reached a stable release means I might actually consider writing some code in it...
 
I think rust will have a very positive impact, even if the most it ever achieves is "niche language".

For example, the idea of explicitly marked "unsafe" sections of code being the only places you allow pointer manipulation (etc) is an idea that could and should be adopted by C++. (I imagine a "#pragma unsafe" define, and a compiler flag that freaks the eff out if the pragma isn't present in the compilation unit where pointer manipulation is happening)

And the fact it's finally reached a stable release means I might actually consider writing some code in it...

The issue is that all those things would be opt-in only. The C++ language committee is very conservative when it comes to language changes like that (rightfully so, to some degree). You even have people from IBM asking the C++ language comittee not to remove digraphs and trigraphs from a future C++ standard (not sure which one, think it was C++17) because some of their dinosaur mainframes still use EBCDIC. So I think having a fresh start, away from all the C++ cruft that's accumulated over the last ~30 years is pretty nice.
 
The issue is that all those things would be opt-in only. The C++ language committee is very conservative when it comes to language changes like that (rightfully so, to some degree). You even have people from IBM asking the C++ language comittee not to remove digraphs and trigraphs from a future C++ standard (not sure which one, think it was C++17) because some of their dinosaur mainframes still use EBCDIC. So I think having a fresh start, away from all the C++ cruft that's accumulated over the last ~30 years is pretty nice.
They would be opt in, but that's fine and entirely in line with the C++ approach. Part of the "cruft" that's accumulated over 30 years is the toolset/infrastructure that no other native language is going to be able to match for a long time.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Is there a TLDR version of why Rust is so good for someone that hasn't followed it at all?
 

Sandfox

Member
I need to output ever permutation for a set of numbers without any repetitions and I'm struggling to figure out a way to prevent the repetitions from printing.
 
Can anyone give me some information on cycle time vs clock rate relating to data paths/multicycle data paths? I also want to know on how to find latency and a cycle time of a pipeline? I have a final this week relating to these questions.
 

mooooose

Member
Can anyone give me some information on cycle time vs clock rate relating to data paths/multicycle data paths? I also want to know on how to find latency and a cycle time of a pipeline? I have a final this week relating to these questions.
In a single cycle data path, there is a critical path. That is, the "longest" route in time will determine how long the enter path must take.

In a multicycle data path, everything is broken into stages. The longest stage determines how long each stage will have to be.

In a pipelined data path, it's the same as multicycle. In the PLDP, you can't skip stages (ie a J instr takes 3 stages in MCDP in comparison to PLDP), each instr must go through each stage in the pipeline. This is to keep everything synchronized in the pipeline.

So, you look at the how many cycles each TYPE of instr takes, and their percentage in an instr set. From there, you can calculate the average CPI, or cycles per instruction. (Cycles/Instr)

Clock rate is how many cycles can be done per second (Cycles/Second). The fast the clock rate, the more Cycles can be done per second, which means it will get through those instructions faster, as instructions are made up of multiple cycles.

Clock time is the amount of time it will take a processor to complete a set of instructions. This is just in seconds. It's the Clock Cycle Time * CPU Clock Cycles, or CPU Clock Cycles / Clock Rate (which makes sense, because it's the total number of clock cycles it needs to do, divided by how many it can do in a second).

Using these tools and the information given in problems, and doing a lot of unit matching, you should be able to solve practice problems easily.

Not sure about latency, I'm assuming you just compare the performance between two machines and that should be enough. You can do that just by comparing them as ratios.

Hope this helps, I have my final on it tomorrow too. Good luck dude!
 
Top Bottom