• 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

alejob

Member
Its a software package, it has portlets kinda like the old iGoogle page.


Those notes from the help(posted above) say... "Since you can't get to the code without modifying the entire portlet" I'm sure that means recompiling a bunch of stuff. The code grabs data from SQL database.

So somehow I have to hide columns 4 thru9 in that table since they will always have zeroes.
 

Slavik81

Member
Incidentally I see most C++ style guides (and some linters) teach that treating bounds as signed is inherently better for many of the reasons you stated. This is based on an implicit assumption that overflow is rarer than having a negative iterator value. Not necessarily a bad assumption in practical use, but I wish they would state it explicitly.
In C++, I would use unsigned. Mixed signed / unsigned comparisons can be detected and warned about by the compiler, which means you can save signed values for just those cases without worrying you'll forget to deviate from your default style.

Usually my conditions are based on size_t anyways.

The "unsigned" version creates a real concern of accidental underflow when someone chooses to decrement the loop counter inside the loop in some special case; the "int" version works correctly when that happens, while the "unsigned" version blows up.
It won't necessarily blow up. The standard says 0u - 1u == UINT_MAX
 

Slavik81

Member
That's exactly how it blows up - you intend to get zero repetitions of the loop and you get UINT_MAX repetitions instead.
Oh, sorry. I thought you meant the decrement itself. Though, I'd probably call that hanging rather than blowing up.

Of course, if you're playing with your index while in the loop, you're asking for trouble. That sort of thing screams 'dangerous' to me.
 

MNC

Member
I want something nice to back my code up to that is not Dropbox. Personally, I'd like to use a repository for svn or git even though I do all my hobby projects solo and there's hardly any need for them. I'm not sure I want to put something online on git for everyone to see either. What do you guys mostly do?
 

Water

Member
I want something nice to back my code up to that is not Dropbox. Personally, I'd like to use a repository for svn or git even though I do all my hobby projects solo and there's hardly any need for them. I'm not sure I want to put something online on git for everyone to see either. What do you guys mostly do?

Use version control, of course. Just make an account at Bitbucket and stick your git repos there. Unlike Github, they allow private repos for free users, no time limit or anything. The only limitation that has affected me is that the free accounts can only share their private repos to a maximum of 4 other people.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I want something nice to back my code up to that is not Dropbox. Personally, I'd like to use a repository for svn or git even though I do all my hobby projects solo and there's hardly any need for them. I'm not sure I want to put something online on git for everyone to see either. What do you guys mostly do?

If you are a student you can get an account with Github that allows for I think 5 private repos. Either that or utilize Bitbucket like Water suggested.
Version control with either one is an excellent thing to learn.

https://education.github.com/
 

usea

Member
I want something nice to back my code up to that is not Dropbox. Personally, I'd like to use a repository for svn or git even though I do all my hobby projects solo and there's hardly any need for them. I'm not sure I want to put something online on git for everyone to see either. What do you guys mostly do?
I put my code on github. There's no reason to care if people look at it. You shouldn't be embarrassed or self-conscious about your code, even when it's bad. Almost all code is bad, even the best code. Programming is hard and humans are bad at it.

That said, bitbucket has free private repositories.
 

fader

Member
Depends on what qualifies as good, but it's my language of choice and I use it a lot. Running into any issues you need help with?

im doing this project where i have to code a program with arrays that enables trading stock, what im lost at is how do i code a function that simulates someone buying a stock since i can only return one integer. cause i have to have 2 arrays one with the stock name, one with the stock price (pilled up for each time they purchase a stock), and i guess he wants me to make an integer for total value of all stocks.
 

Kopite

Member
Not sure if this is the right thread to ask but I'm helping a friend set up a website to promote an app his building. I'm a CS freshman who has a basic knowledge of html and css. Another friend has set up the server and installed wordpress on it. I'm using a free theme on it now but when I go to the editor i can only see php files and css files. I can edit some of the css elements but I'm unable to change stuff like the logo image sizes as I only know how to that on html. Is the theme I'm running on the site using php for all that instead of html coding? If so , will it be difficult to learn how to edit those php files?

Here's the site in question:

http://wp.tanya.com.my/

One of the things I'd like to do but don't know how is alter the size of the logo in the top right corner.

Cheers.
 
So I'm ok at C++ and I'm going to carry on learning to hopefully do a project in Unreal Engine 4 before the end of this year. Big goals, will they be reached? Hopefully.

The main question I have is,
How/Where do I start with any server side language. I've tried many times to learn Ruby on Rails or NodeJS but to no luck. Everything just confuses me!
I'm looking to learn NodeJS preferably but any overall tips will be very much welcome.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
im doing this project where i have to code a program with arrays that enables trading stock, what im lost at is how do i code a function that simulates someone buying a stock since i can only return one integer. cause i have to have 2 arrays one with the stock name, one with the stock price (pilled up for each time they purchase a stock), and i guess he wants me to make an integer for total value of all stocks.

Can you use a hash table instead?

I'm not overly familiar with them, but from what I understand you can assign a key to the client, then store the clients stock name + stock price at that key's location. This might be easier then dealing with two separate arrays.
 

Water

Member
im doing this project where i have to code a program with arrays that enables trading stock, what im lost at is how do i code a function that simulates someone buying a stock since i can only return one integer. cause i have to have 2 arrays one with the stock name, one with the stock price (pilled up for each time they purchase a stock), and i guess he wants me to make an integer for total value of all stocks.
You have to go in much more detail. Is this a function you figured out you want to write, or something you were explicitly told to write? If the latter, what has your instructor specified about the function exactly? What is the output this function should produce, and what inputs should it take exactly? Is the "function" supposed to do side effects like reading input or printing, and if so, what?

You certainly can return more than one value from a Python function.
 

fader

Member
Can you use a hash table instead?

I'm not overly familiar with them, but from what I understand you can assign a key to the client, then store the clients stock name + stock price at that key's location. This might be easier then dealing with two separate arrays.

actually, i meant to say list not array sorry.

but thats basically what a hash table is right? if so then yea thats what i am suppose to do but i am stuck at how to simulate a customer buying a stock

You have to go in much more detail. Is this a function you figured out you want to write, or something you were explicitly told to write? If the latter, what has your instructor specified about the function exactly? What is the output this function should produce, and what inputs should it take exactly? Is the "function" supposed to do side effects like reading input or printing, and if so, what?

You certainly can return more than one value from a Python function.

he didn't specify what a function should do just what the end result of the project should be but im trying to make a function that enables the user to buy a stock. the whole project is pretty much "code how you want it but it should do _____"

i wish there was a way for me to upload the project sheet that might give you guys a better undertanding
 

Water

Member
he didn't specify what a function should do just what the end result of the project should be but im trying to make a function that enables the user to buy a stock.
We can't possibly know what "buy a stock" actually means in terms of your program, because we don't know what data your program deals with. Is one "stock" defined by a name and price? Is there an unlimited amount of every stock available? Does the price change? Is there only one user? Does that user have a specific balance of money with which to buy stocks? Does your program have to remember which stocks the user has bought, and display them somehow?
 

fader

Member
We can't possibly know what "buy a stock" actually means in terms of your program, because we don't know what data your program deals with. Is one "stock" defined by a name and price? Is there an unlimited amount of every stock available? Does the price change? Is there only one user? Does that user have a specific balance of money with which to buy stocks? Does your program have to remember which stocks the user has bought, and display them somehow?

so far its just for one user. there are 3 list that contains info the available stocks. one list contains the name of the company, one contains the stock name, and the other contains the the price.

e.g. a = [microsoft,sony,nintendo] b = [MST,SNY,NIN] c = [35.60,60.75,21.00]

i'm sure you know that at 0 from each list equals microsoft, at 1 from each list equals sony, and at 2 is nintendo

i'm thinking of making a list that contains maybe a counter for each time the user buys a stock for each company an returning that list cause i have to be able to print out to the user how many of each stock they purchased, and the total amount each are worth

EDIT: heres a copy of the project maybe this will help. please look over it if you can
 

cyborg009

Banned
Hey I'm doing something in powershell to find the folders in a directory and list with sizes but I keep running into a error

Code:
$Directory = Read-Host "Enter your directory"

$colItems = (Get-ChildItem $Directory |  {$_.Attributes -match 'Directory'} |Measure-Object -Property Length -Sum  )
The bit after | is suppose to show the sizes but I don't know what I'm doing wrong.
 

oxrock

Gravity is a myth, the Earth SUCKS!
im doing this project where i have to code a program with arrays that enables trading stock, what im lost at is how do i code a function that simulates someone buying a stock since i can only return one integer. cause i have to have 2 arrays one with the stock name, one with the stock price (pilled up for each time they purchase a stock), and i guess he wants me to make an integer for total value of all stocks.

is returning a single int a limitation of the assignment?

actually, i meant to say list not array sorry.

but thats basically what a hash table is right? if so then yea thats what i am suppose to do but i am stuck at how to simulate a customer buying a stock



he didn't specify what a function should do just what the end result of the project should be but im trying to make a function that enables the user to buy a stock. the whole project is pretty much "code how you want it but it should do _____"

i wish there was a way for me to upload the project sheet that might give you guys a better undertanding

ok, so you're writing a program consisting of more than a single function I'm assuming. I'm assuming you're provided with a list of stocks and then you have to find a way for a user to pick it from the list for a certain cost and update the list? Mostly guess work here, we'd need more specifics to be able to help. Also, a python dictionary is a hashtable.


Edit: looks like the assignment mostly wants to teach you how to work with lists and especially lists with lists within lists, etc. Stacking lists like that can be hard to wrap your mind around at first so don't be ashamed to draw it out. So the primary list for example would be a list of all the customers of the stock company. Within that list would be something like the customer's email, money amount, list of stocks, etc for every position on the list. Then you just need to learn how to navigate the list structure you create and return the values asked for.

edit2: I notice your assignment is due tomorrow, way to procrastinate! Goodluck
 

fader

Member
is returning a single int a limitation of the assignment?



ok, so you're writing a program consisting of more than a single function I'm assuming. I'm assuming you're provided with a list of stocks and then you have to find a way for a user to pick it from the list for a certain cost and update the list? Mostly guess work here, we'd need more specifics to be able to help. Also, a python dictionary is a hashtable.


Edit: looks like the assignment mostly wants to teach you how to work with lists and especially lists with lists within lists, etc. Stacking lists like that can be hard to wrap your mind around at first so don't be ashamed to draw it out. So the primary list for example would be a list of all the customers of the stock company. Within that list would be something like the customer's email, money amount, list of stocks, etc for every position on the list. Then you just need to learn how to navigate the list structure you create and return the values asked for.

edit2: I notice your assignment is due tomorrow, way to procrastinate! Goodluck

hahaha! i didn't procrastinate i just didnt know how to do it!!! :(

thanks for the help,i think i got it

EDIT: So you're saying the primary list should be a = [[email,social security,fist name, last name, password],[email,social security,fist name, last name, password],[email,social security,fist name, last name, password]]
and do i call that list with double brackets if i need the email or last name, etc?
if that the right way to do list in list then how does that effect buying stocks exactly?
 

Ambitious

Member
What the heck.
A few days ago, I wrote a tiny bookmarklet for my iPhone to search in Wikipedia and open the result in Wikipanion. It's just the following two lines, and worked as expected:

Code:
javascript: var input = prompt("Search Wikipedia:", "");
window.open("wikipanion:///" + input);

Today I added a check for empty strings so it doesn't open Wikipanion after tapping Cancel. It doesn't work anymore, it simply opens a new, empty tab. No syntax errors or anything. Even when I use the old version posted above, the result is the same. Blank new tab.

How is that even possible? I'm confused. Could it be that iOS somehow forgot the app's URL scheme?
 

hateradio

The Most Dangerous Yes Man
Maybe you should put it inside an anonymous function.

Code:
javascript:(function() { var input = prompt('Search Wikipedia', ''); if (input) { window.open('wikipanion:///' + input); } }());
 

oxrock

Gravity is a myth, the Earth SUCKS!
hahaha! i didn't procrastinate i just didnt know how to do it!!! :(

thanks for the help,i think i got it

EDIT: So you're saying the primary list should be a = [[email,social security,fist name, last name, password],[email,social security,fist name, last name, password],[email,social security,fist name, last name, password]]
and do i call that list with double brackets if i need the email or last name, etc?
if that the right way to do list in list then how does that effect buying stocks exactly?

Well i believe for your assignment, within each individual's list there should also contain a list of their stocks but I believe you get the general idea.
Kind of worried if you don't know how to call items within lists with an assignment like this. But for example, list[2][1] would call the 2nd item in the 3rd position of the outer list.
 

fader

Member
Well i believe for your assignment, within each individual's list there should also contain a list of their stocks but I believe you get the general idea.
Kind of worried if you don't know how to call items within lists with an assignment like this. But for example, list[2][1] would call the 2nd item in the 3rd position of the outer list.

ah ok. well i mean he never went over list inside of list. we just spend most time on making parallel lists.
 

oxrock

Gravity is a myth, the Earth SUCKS!
Hard to know what you've been taught and how you're expected to tackle this assignment. I for one would be all over dictionaries for this but your assignment explicitly states that lists are to be used. efficiency isn't really a big concern for such a small amount of data to keep track of. Whatever system you can think up that works, go for it.
 

Water

Member
so far its just for one user. there are 3 list that contains info the available stocks. one list contains the name of the company, one contains the stock name, and the other contains the the price.

e.g. a = [microsoft,sony,nintendo] b = [MST,SNY,NIN] c = [35.60,60.75,21.00]

i'm sure you know that at 0 from each list equals microsoft, at 1 from each list equals sony, and at 2 is nintendo

i'm thinking of making a list that contains maybe a counter for each time the user buys a stock for each company an returning that list cause i have to be able to print out to the user how many of each stock they purchased, and the total amount each are worth
Pretty much, yeah. I'm not sure if you meant this with the above, but you can just make a list with a zero for every kind of stock:
Code:
howManyStocksBought = [0] * len(stockNames)
and increase the total at the appropriate index when the user buys that stock.
Then e.g. printing a list of all the stocks bought is just a matter of going through that list, and every time you find a non-zero at some index, you can get the name and price of the stock from the other lists by using the same index.
 

Garcia

Member
Oh shit guys, you were absolutely right.

It's been 3 weeks since I started learning Java and I'm just about to create my own classes. Now that I've reached a competent beginner level, watching tutorials of other languages like C++ make complete sense. The only thing that seems a little strange is the syntax, but the structure, functionality and behavior of methods is strikingly similar.

I will, however, hold on until I reach a high-intermediate level of Java before I venture into other languages; it really is important to have a very solid ground in order to prevent bad habits down the road.

I feel so excited and even more motivated to complete the Java course now. Computer Science is such a beautiful, creative and expansive world. Don't know why it took me so long to catch up.
 

oxrock

Gravity is a myth, the Earth SUCKS!
Oh shit guys, you were absolutely right.

It's been 3 weeks since I started learning Java and I'm just about to create my own classes. Now that I've reached a competent beginner level, watching tutorials of other languages like C++ make complete sense. The only thing that seems a little strange is the syntax, but the structure, functionality and behavior of methods is strikingly similar.

I will, however, hold up until I reach a high-intermediate level of Java before I venture into other languages; it really is important to have a very solid ground in order to prevent bad habits down the road.

I feel so excited and even more motivated to complete the Java course now. Computer Science is such a beautiful, creative and expansive world. Don't know why it took me so long to catch up.
That's awesome, I'm newer myself. The more I know, the more I know I need to know, haha.
 

Water

Member
It's been 3 weeks since I started learning Java and I'm just about to create my own classes. Now that I've reached a competent beginner level
Congrats on being on the road to learning programming, and hope you like it here!
Based on how your paragraph continues, unconscious incompetence might be a better descriptor at this point though:
watching tutorials of other languages like C++ make complete sense. The only thing that seems a little strange is the syntax, but the structure, functionality and behavior of methods is strikingly similar.
Sure, there are commonalities, but those two languages are actually strikingly different. One thing where they are similar a lot of the time is... syntax. C++ gives plenty of ammunition for everyone to shoot their own foot, but Java programmers are in for a special treat because so many things look familiar and safe.
I will, however, hold on until I reach a high-intermediate level of Java before I venture into other languages; it really is important to have a very solid ground in order to prevent bad habits down the road.
A+++++ decision!
 

Ambitious

Member
Maybe you should put it inside an anonymous function.

Code:
javascript:(function() { var input = prompt('Search Wikipedia', ''); if (input) { window.open('wikipanion:///' + input); } }());

I'm a Javascript amateur - what difference is this supposed to make?

Anyway, the result is the same. I also noticed that going back to the homescreen and reopening Safari triggers the "Do you want to open the link in Wikipanion?" dialog. Just weird.
 

iapetus

Scary Euro Man
C++ gives plenty of ammunition for everyone to shoot their own foot, but Java programmers are in for a special treat because so many things look familiar and safe.

And it's not like it's much better going the other way - the vilest Java code I've ever had the joy of working with has all been written by people who came to Java from C++ backgrounds. :D It's not generally as immediately lethal, because Java tends to be a lot better at preventing you from riddling your own foot with virtual bullets, but the code stink can get pretty bad...
 

Water

Member
And it's not like it's much better going the other way - the vilest Java code I've ever had the joy of working with has all been written by people who came to Java from C++ backgrounds. :D It's not generally as immediately lethal, because Java tends to be a lot better at preventing you from riddling your own foot with virtual bullets, but the code stink can get pretty bad...
Out of curiosity, can you give examples of what kind of stuff they do poorly? I can't think of any reason why a decent C++ programmer would write stinky code in Java, unless it's in a futile effort to do more generic programming than Java is capable of or something. So my gut feeling is these would have been "C/C++" or otherwise lousy C++ programmers.
 

Garcia

Member
Congrats on being on the road to learning programming, and hope you like it here!
Based on how your paragraph continues, unconscious incompetence might be a better descriptor at this point though.

Thank you very much for linking to that wiki. It is very interesting how those 4 stages can be equally applied to several layers of learning.

Less then 2 weeks ago I was pulling my hairs out trying to understand how 2 nested for loops were able to create a patterned checkerboard. Fast forward to last night and I was actually applying nested for loops as constructors since now I perfectly understand how they work.

I also just did my second program using stepwise refinement and the difference it makes is just staggering. :O
 

iapetus

Scary Euro Man
Out of curiosity, can you give examples of what kind of stuff they do poorly? I can't think of any reason why a decent C++ programmer would write stinky code in Java, unless it's in a futile effort to do more generic programming than Java is capable of or something. So my gut feeling is these would have been "C/C++" or otherwise lousy C++ programmers.

Bad exception handling is the one that normally stands out - a tendency to do it at the wrong scope and with the wrong granularity. Could be a C thing, I suppose - you never really get a chance go back and audit the experience of these people to see how real their C++ experience was. ;)
 

Water

Member
Bad exception handling is the one that normally stands out - a tendency to do it at the wrong scope and with the wrong granularity.

Ah, that makes sense. I'd probably turn out to be one of those programmers if put to the test. :)
I have practically no experience in writing explicit exception handling, and I don't think that's very uncommon for C++ programmers. Some work with codebases where exceptions are banned, or altogether disabled; some work with code where the correct response to any exception is letting the program die, so no need to catch it.

OTOH, a good C++ programmer from an environment where exceptions do matter should not be used to writing a lot of explicit exception handling, either. They'd only use it for whatever RAII can't handle.

Still, even if they mess up exception handling, how can that be in the same league as the stereotypical Java programmer doing C++? At least the Java code would work until an exception occurred, whereas the C++... :p
 

upandaway

Member
Bad exception handling is the one that normally stands out - a tendency to do it at the wrong scope and with the wrong granularity. Could be a C thing, I suppose - you never really get a chance go back and audit the experience of these people to see how real their C++ experience was. ;)
Looks like I'm going to have trouble wrapping my head around writing in C++ when I try in the future. I currently can't imagine writing something without using exceptions.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Ah, that makes sense. I'd probably turn out to be one of those programmers if put to the test. :)
I have practically no experience in writing explicit exception handling, and I don't think that's very uncommon for C++ programmers. Some work with codebases where exceptions are banned, or altogether disabled; some work with code where the correct response to any exception is letting the program die, so no need to catch it.

OTOH, a good C++ programmer from an environment where exceptions do matter should not be used to writing a lot of explicit exception handling, either. They'd only use it for whatever RAII can't handle.

Still, even if they mess up exception handling, how can that be in the same league as the stereotypical Java programmer doing C++? At least the Java code would work until an exception occurred, whereas the C++... :p

What do the stereotypical Java programmers writing C++ do wrong?
 

tokkun

Member
What do the stereotypical Java programmers writing C++ do wrong?

Memory management and object lifetimes is the big one. Java programmers are not taught to reason about object scope and lifetime as a principle consideration. Avoiding memory leaks, pointer safety, how to effectively use destructors to manage resources, when it makes sense to allocate from the stack vs the heap...all that good stuff.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Memory management and object lifetimes is the big one. Java programmers are not taught to reason about object scope and lifetime as a principle consideration. Avoiding memory leaks, pointer safety, how to effectively use destructors to manage resources, when it makes sense to allocate from the stack vs the heap...all that good stuff.

Ahh okay, I can see how that would cause some pretty large issues. Thanks for the info.
 

Onemic

Member
Is it possible to step through a Javascript program like you can in C++? It seems like debugging in Javascript is an exercise in frustration because you never know where your error is. A big part of the reason why I absolutely hate the language now.
 

usea

Member
Is it possible to step through a Javascript program like you can in C++? It seems like debugging in Javascript is an exercise in frustration because you never know where your error is. A big part of the reason why I absolutely hate the language now.
If this is js running in the browser, chrome, opera and firefox have great debugging environments. The developer console in chrome is widely used to debug javascript. Just hit F12 to open the console, click the "sources" tab at the top, click "sources" again in the tree view on the left, select the page or js file you're looking for, and click on a line to set a breakpoint. When the javascript hits that point, you can step through line-by-line with the controls in the upper right (F10 is next line, F8 is continue). You can also hit ESC in the developer console to bring up the actual console, and enter lines of javascript that will run in the current environment. For example if your code has a global variable `accounts` you can just type `accounts` and hit enter (no semicolon) and it will show you the current value of that variable. You can run functions or whatever you want.

Of course, you could also unit test your javascript, using phantom js and a bunch of other tools. But that gets a lot more complicated. Payoff is worth it though.
 
So all you guys who use a Mac, what are some of your favorite tools? Not so much language specific IDEs, more like text editors, productivity tools, etc.

I just got a Mac and while I got my Windows VM set up for my dev stuff there, I'm trying to get my Mac set up for dev work.

Edit: Sorry, I know its a bit off-topic but its the best place I could think of coming without starting a new thread.
 
So all you guys who use a Mac, what are some of your favorite tools? Not so much language specific IDEs, more like text editors, productivity tools, etc.

I just got a Mac and while I got my Windows VM set up for my dev stuff there, I'm trying to get my Mac set up for dev work.

Edit: Sorry, I know its a bit off-topic but its the best place I could think of coming without starting a new thread.

http://brew.sh/
http://brew.sh/
http://brew.sh/

I love Sublime Text2 as well.
 

sdijoseph

Member
Has anyone here had a problem with visual studio 2013 where every time you opened it, the graphics would load very choppy and you couldn't edit your code at all?
 

iapetus

Scary Euro Man
Still, even if they mess up exception handling, how can that be in the same league as the stereotypical Java programmer doing C++? At least the Java code would work until an exception occurred, whereas the C++... :p

That's not necessarily a good thing. Bugs are easier to fix the quicker they surface. Java programmers coding badly in C++ tend to do things that show up very quickly and easily. C++ programmers coding badly in Java tend to do things that fail very badly and silently. The severity of the problem is a lot lower, but the pain of tracking it down tends to be a lot worse. "catch (Exception e) {}" always makes me shiver with dread. :p
 
Top Bottom