• 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.
If I had a beginning and end point, how could I calculate an arc between the two? Trying to accomplish something in Unity (c#) that would give me an arc (arbitrary arc, doesn't need to be anything specific) and don't know how to go about it.

Assuming the end points and the arc lies on a normal circle and it's not some sort of weird distorted shape...

1) Get the center of the circle
2) Create vectors to the two points
3) Derive the angle between them (see: dot product)
4) Divide that angle by 2pi
5) Multiply by the circumference of the circle

Only problem with this approach is that it only works on angles bellow pi, due to the nature of the cos/arccos function in most programming languages. You need another line to check if you want the inner angle (say, 60 degrees) or the outer angle (300 degrees).
 

Anustart

Member
Assuming the end points and the arc lies on a normal circle and it's not some sort of weird distorted shape...

1) Get the center of the circle
2) Create vectors to the two points
3) Derive the angle between them (see: dot product)
4) Divide that angle by 2pi
5) Multiply by the circumference of the circle

Only problem with this approach is that it only works on angles bellow pi, due to the nature of the cos/arccos function in most programming languages. You need another line to check if you want the inner angle (say, 60 degrees) or the outer angle (300 degrees).

All the angles should be below pi as there's really no situation in which the arc would be half a circle.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
One amendment, since you're workng with radians anyway you can shorten 4 and 5 to just one step since you're dividing by 2pi and multiplying by pi2r. So it's θr.
 

BreakyBoy

o_O @_@ O_o
I'm forcing myself to learn it this quarter, and have made it over the initial hump where it's no longer a barrier to productivity. I like being able to essentially multiply commands, but still prefer sublime for it's modern gui, autocomplete, dir lists, and some other features.

Writing code in vim does make me feel like a badass though, and seems to be somewhat easier on the wrists.

Sublime has a Vintage mode and there are some common packages that make it even more vi-like: https://www.sublimetext.com/docs/2/vintage.html

As a side-note: if you're pretty comfortable with Sublime and you haven't explored the wide array of plugin/packages that are available, you're missing out.
 

Jackben

bitch I'm taking calls.
Really confused on templates. Trying to create a templated class (CircleT) that has basic attributes for xCrd, yCrd and radius all templated with methods for getting circumference and area. Need to use operator overloading to enable main driver results from statements like Circle<int> c1; Circle<int> c2; c1 + c2; etc.

I have no idea what I'm doing though and spent about an hour just trying to get the header to compile and now I have a bunch of error C2228 "left of '.xCrd' must have class/struct/union". Probably because I haven't set up the syntax correctly.

No idea what the fudge I am doing, just really confused. Any advice is again greatly appreciated.

http://pastebin.com/44nFuUDM
 
I'm forcing myself to learn it this quarter, and have made it over the initial hump where it's no longer a barrier to productivity. I like being able to essentially multiply commands, but still prefer sublime for it's modern gui, autocomplete, dir lists, and some other features.

Writing code in vim does make me feel like a badass though, and seems to be somewhat easier on the wrists.

There are several plugins available that you can add to VIM to make it that perfect flavor that suits your need.

Does anyone know a good resource to learn regular expressions? I really need to step up my game a little bit in that area.


If you are comfortable with ST, why do you feel the need to learn vim? Nerd cred?

When viewing and editing files on a remote server with just the terminal, being familiar with the basic VIM commands are real helpful.
 

BreakyBoy

o_O @_@ O_o
Alternatively, you can get autocomplete and directory listings in vim with plugins.

Agreed. That's also very helpful to know/use, even if you do still end up preferring another editor, because:

When viewing and editing files on a remote server with just the terminal, being familiar with the basic VIM commands are real helpful.

As much as I like vim though, I remain curious about emacs, so I'm going to give that a try next.
 

Water

Member
Really confused on templates. Trying to create a templated class (CircleT) that has basic attributes for xCrd, yCrd and radius all templated with methods for getting circumference and area. Need to use operator overloading to enable main driver results from statements like Circle<int> c1; Circle<int> c2; c1 + c2; etc.

I have no idea what I'm doing though and spent about an hour just trying to get the header to compile and now I have a bunch of error C2228 "left of '.xCrd' must have class/struct/union". Probably because I haven't set up the syntax correctly.

No idea what the fudge I am doing, just really confused. Any advice is again greatly appreciated.

http://pastebin.com/44nFuUDM
When asking for help, you should post the full actual error messages including what rows they come from, and the main you're using to test. And debugging in general: when confused, narrow the cause down by commenting out everything until you are left with a minimal failing case, e.g. just one operator in the class. Don't write 300 lines of code and then just look at it to find out why it doesn't work.
At a glance, I would suspect your function declarations which say "const CircleT& xxx" instead of "const CircleT<T>& xxx".
 
I don't really ever come in here, but I thought you all might enjoy this article.

It all seems pretty accurate

A highlight:
Once upon time I read a post that said to become a good programmer you need to accept the fact that you are an awful programmer because everyone is an awful programmer and all programming languages are awful and then maybe in 10-15 years you become a decent programmer and I have lived by it ever since.
 
Curious, does anyone know a good XML/android tutorial site?

Rather, a good configuration for the virtual android on a slow computer? It doesn't even load on two computers I have(one is old and the other is weak). Hard to play around with it if I can't even load how it looks
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Curious, does anyone know a good XML/android tutorial site?

Rather, a good configuration for the virtual android on a slow computer? It doesn't even load on two computers I have(one is old and the other is weak). Hard to play around with it if I can't even load how it looks

I've found that even on a fast computer the Android emulator is very, very slow. It's best to just get a hold of an Android device and doing your testing through that.
 

nan0

Member
Rather, a good configuration for the virtual android on a slow computer? It doesn't even load on two computers I have(one is old and the other is weak). Hard to play around with it if I can't even load how it looks

You could take a look at Genymotion. There is a free version that is enough for playing around, and the last time I tried it it was way faster than the Google-supplied Emulator. Can't say how it runs on a slower computer though.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Could someone explain to me this line?

Code:
(subStartR, subNumR) = (0, problem.numRow)

This is in Python 3, I believe. The full code is:

Code:
def algorithm1(problem, trace = None):
    # if it's empty, we're done 
    if problem.numRow <= 0 or problem.numCol <= 0:
        return None

    # the recursive subproblem will involve half the number of columns
    mid = problem.numCol // 2

    # information about the two subproblems
    (subStartR, subNumR) = (0, problem.numRow)
    (subStartC1, subNumC1) = (0, mid)
    (subStartC2, subNumC2) = (mid + 1, problem.numCol - (mid + 1))

    subproblems = []
    subproblems.append((subStartR, subStartC1, subNumR, subNumC1))
    subproblems.append((subStartR, subStartC2, subNumR, subNumC2))

    # get a list of all locations in the dividing column
    divider = crossProduct(range(problem.numRow), [mid])

    # find the maximum in the dividing column
    bestLoc = problem.getMaximum(divider, trace)

    # see if the maximum value we found on the dividing line has a better
    # neighbor (which cannot be on the dividing line, because we know that
    # this location is the best on the dividing line)
    neighbor = problem.getBetterNeighbor(bestLoc, trace)

    # this is a peak, so return it
    if neighbor == bestLoc:
        if not trace is None: trace.foundPeak(bestLoc)
        return bestLoc
   
    # otherwise, figure out which subproblem contains the neighbor, and
    # recurse in that half
    sub = problem.getSubproblemContaining(subproblems, neighbor)
    if not trace is None: trace.setProblemDimensions(sub)
    result = algorithm1(sub, trace)
    return problem.getLocationInSelf(sub, result)
 

miniMacGuru

Neo Member
Could someone explain to me this line?

Code:
(subStartR, subNumR) = (0, problem.numRow)

I belive it's just multi-variable assignment. It should be the same as

Code:
subStartR = 0
subNumR = probelm.numRow

Putting it one line just lets you condense the code a bit. It's a style thing.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
I figured, thanks. Seems like the only point of divvying the assignment up that way is to make it clearer what was happening in the algorithm.
 

oxrock

Gravity is a myth, the Earth SUCKS!
Could someone explain to me this line?

Code:
(subStartR, subNumR) = (0, problem.numRow)

This is in Python 3, I believe. The full code is:
Just a simple double assignment.
subStartR = 0
subNumR = problem.numRow

edit: apparently I had left this tab open for a while, didn't notice it'd already been answered.
 

Jackben

bitch I'm taking calls.
When asking for help, you should post the full actual error messages including what rows they come from, and the main you're using to test. And debugging in general: when confused, narrow the cause down by commenting out everything until you are left with a minimal failing case, e.g. just one operator in the class. Don't write 300 lines of code and then just look at it to find out why it doesn't work.
At a glance, I would suspect your function declarations which say "const CircleT& xxx" instead of "const CircleT<T>& xxx".
Thank you for your help on my project, that was the major problem that was wrong. I will also attempt to be more clear with future issues. If I could borrow another second of your generous time:

I can get the operators to work correctly with xCrd and yCrd. The new problem is with utilizing the circumference, radius and area functions. I had to comment out getCircumference as it wouldn't compile. Here is the error when getCircumference isn't commented out:

Code:
Error	1	error C3867: 'CircleT<T>::getCircumference': function call missing argument list; use '&CircleT<T>::getCircumference' to create a pointer to member	g:\vcprojects\prj05\circlet.h	131
Error	2	error C3867: 'CircleT<T>::getCircumference': function call missing argument list; use '&CircleT<T>::getCircumference' to create a pointer to member	g:\vcprojects\prj05\circlet.h	131
Error	3	error C3867: 'CircleT<T>::getCircumference': function call missing argument list; use '&CircleT<T>::getCircumference' to create a pointer to member	g:\vcprojects\prj05\circlet.h	131

Also getArea doesn't return the right values sometimes for some reason.

Driver file is also included this time.

http://pastebin.com/bVQDih1m
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Continuing the Python questions from earlier, what the hell is this line?
Code:
# get a list of all locations in the dividing column
divider = crossProduct(range(problem.numRow), [mid])
I assume divider is an array, and [mid] is an array instantiated with # of elements = to mid.

But where is this "crossProduct" function coming from and why would anyone name a function that operates on arrays of arbitrary length "crossProduct"?
 

miniMacGuru

Neo Member
Continuing the Python questions from earlier, what the hell is this line?
Code:
# get a list of all locations in the dividing column
divider = crossProduct(range(problem.numRow), [mid])
I assume divider is an array, and [mid] is an array instantiated with # of elements = to mid.

But where is this "crossProduct" function coming from and why would anyone name a function that operates on arrays of arbitrary length "crossProduct"?

crossProduct doesn't ring any bells as a standard python function that I'm familiar with. Are you importing any other files/packages?

In the function call though, range(problem.numRow) becomes (pretty much) a list of the numbers [0 1 2 3 ... (problem.numRow - 1)]. [mid] becomes a list with a single element. I'm really not sure what the function does, so I can't speculate what divider ends up as.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Okay I'm dumb, the function crossProduct is at the bottom of algorithms.py.

Code:
def crossProduct(list1, list2):
    """
    Returns all pairs with one item from the first list and one item from 
    the second list.  (Cartesian product of the two lists.)

    The code is equivalent to the following list comprehension:
        return [(a, b) for a in list1 for b in list2]
    but for easier reading and analysis, we have included more explicit code.
    """

    answer = []
    for a in list1:
        for b in list2:
            answer.append ((a, b))
    return answer
Thanks again.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Within the algorithm, it generates a list of coordinates (x,y) of a column of a matrix, the so called "divider".
 

tokkun

Member
I thought the point of mechanical keyboards was the satisfying clackclackclackclackclackclackclack

I like both the tactile feedback and the audible feedback, but at work I use a silent* mechanical keyboard out of consideration for my co-workers.

*Even the silent ones are considerably louder than a typical membrane keyboard.
 
You could take a look at Genymotion. There is a free version that is enough for playing around, and the last time I tried it it was way faster than the Google-supplied Emulator. Can't say how it runs on a slower computer though.

I've found that even on a fast computer the Android emulator is very, very slow. It's best to just get a hold of an Android device and doing your testing through that.
Thanks guys for the replies. Getting a hold on an android device was better for me.

Is it me or is eclipse buggy for android development? I had XML errors and r.java gone missing so far.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Thanks guys for the replies. Getting a hold on an android device was better for me.

Is it me or is eclipse buggy for android development? I had XML errors and r.java gone missing so far.

Just make the switch to Android Studio instead.
 

BreakyBoy

o_O @_@ O_o
I thought the point of mechanical keyboards was the satisfying clackclackclackclackclackclackclack

Topres (such as that one) are not that loud. And over time, you should learn to type without bottoming out the keys. Once you master that, it's even quieter.

To answer the implied question, it's a comfort thing more than anything. I get far less strain in my hands when I'm using my Happy Hacking Keyboard 2 versus my Macbook's chiclet layout, or any average membrane keyboard.

Honestly, Topres are expensive, but I've been spoiled by my HHKB2. I don't think I can ever go back to anything less. It's a good thing mechanical keyboards are durable.
 
I read through some of the website and replys here, but I don't get it. The keys feel better? Is that it? Is that what makes it worth it?
 
Topres (such as that one) are not that loud. And over time, you should learn to type without bottoming out the keys. Once you master that, it's even quieter.

To answer the implied question, it's a comfort thing more than anything. I get far less strain in my hands when I'm using my Happy Hacking Keyboard 2 versus my Macbook's chiclet layout, or any average membrane keyboard.

Honestly, Topres are expensive, but I've been spoiled by my HHKB2. I don't think I can ever go back to anything less. It's a good thing mechanical keyboards are durable.

I was looking at the HHKB2 but was turned off by the lack of an arrow key. How do you code in something like eclipse? I didn't see any function arrow keys on the description page. Just remap certain buttons?
 

tuffy

Member
I was looking at the HHKB2 but was turned off by the lack of an arrow key. How do you code in something like eclipse? I didn't see any function arrow keys on the description page. Just remap certain buttons?
You hold down a "meta" key (often next to the left alt) and use keys next to "return" as arrows. This chording is also used for PgUp, PgDown, function keys and so on. It keeps the keyboard small but takes some getting used to.
 

Ya no

Member
I'm trying to write a hangman game in C++ and I'm having some trouble converting a char variable to a string and I'm not sure why it's not working. I googled it and found this:

Code:
#include <sstream>
#include <string>
stringstream ss;
string s;
char c = 'a';
ss << c;
ss >> s;

Which I adapted into my own code, but it's still not working. It's telling me:

error C2440: 'initializing' : cannot convert from 'const char [1]' to 'char'
There is no context in which this conversion is possible.

For my code, I have the user enter in a char to the variable letterGuess, then:

Code:
	ss << letterGuess;
	ss >> temp;
Where temp is a string variable.

What could I be doing wrong, any ideas? Is there an easier way to do this? Seems like it shouldn't be giving me this much trouble...


EDIT: Lol fuck me I had the letterGuess variable declared with double quotes instead of single... don't you just hate programming sometimes?
 

BreakyBoy

o_O @_@ O_o
I was looking at the HHKB2 but was turned off by the lack of an arrow key. How do you code in something like eclipse? I didn't see any function arrow keys on the description page. Just remap certain buttons?

You hold down a "meta" key (often next to the left alt) and use keys next to "return" as arrows. This chording is also used for PgUp, PgDown, function keys and so on. It keeps the keyboard small but takes some getting used to.

That's pretty much it, except on the HHKB2 it's a Fn key to the right of the right shift key. Right under Return. I extend my right pinky just slightly to get to it, just as if I was using the right Shift key.

Up = [
Down = /
Left = ;
Right = '

HGxAKK8.jpg


You can just barely see the Fn key layout there on the underside of each key cap.

It definitely takes getting used to, but I'm very much used to it now. And in vim, arrow keys are somewhat redundant anyway, since you're using commands to bounce around pages, words, lines, etc. And if you need fine grain movement, you use HJKL for movement.

It took me about a week to get used to it enough that it didn't really impact productivity much. Now I barely move my wrists at all. Super fast, super comfortable.

The only thing that I occasionally still stumble on is having the tilde to the top-right, instead of to the top-left. Everything else, I have no problems with, and surprisingly, I have no issues switching from that to my Macbook chiclet keyboard when I'm on the go.
 

Cromat

Member
Hello Dev-GAF, I know this is kind of an annoying question but I'd like to hear your estimates.

Say someone wants to create a social network with a nice looking mobile client. Something like Twitter or Snapchat, only obviously on a much smaller scale at first. For that you need to develop:

- The backend (server, database, data manipulation)
- iOS client
- Android client

Can you give me a ballpark figure of how long it will take? Can it be done by a single person (I assume not)? If no, how many people would you need as a minimum?
 

usea

Member
Hello Dev-GAF, I know this is kind of an annoying question but I'd like to hear your estimates.

Say someone wants to create a social network with a nice looking mobile client. Something like Twitter or Snapchat, only obviously on a much smaller scale at first. For that you need to develop:

- The backend (server, database, data manipulation)
- iOS client
- Android client

Can you give me a ballpark figure of how long it will take? Can it be done by a single person (I assume not)? If no, how many people would you need as a minimum?
Estimating is extremely hard (many would say impossible, and not even worth trying). There's a movement against ever trying to estimate software, #noestimates
Here's an example article on the difficulty of doing estimates for development http://blog.robbowley.net/2011/09/21/estimation-is-at-the-root-of-most-software-project-failures/

You need way, way more detail to get a reasonable estimate for that project. I estimate that getting a reasonable estimate would take several days of work. I'm not joking.

With the amount of data in your post, I estimate with about a 5% confidence that the project you're talking about would take one person between 1 and 50 months.
 
Hello Dev-GAF, I know this is kind of an annoying question but I'd like to hear your estimates.

Say someone wants to create a social network with a nice looking mobile client. Something like Twitter or Snapchat, only obviously on a much smaller scale at first. For that you need to develop:

- The backend (server, database, data manipulation)
- iOS client
- Android client

Can you give me a ballpark figure of how long it will take? Can it be done by a single person (I assume not)? If no, how many people would you need as a minimum?
Anything can be done by a single person, given the talent and time.

...which leads to the inherent problem of estimating. I wouldn't say impossible, because IMO madness lies down that road (being 80% sure of where you're going is better than 0% sure. 80% accuracy on your estimates, as a team, is eventually achievable). But very difficult, especially when your dev team isn't set in stone, or just new (people haven't found their niche yet, etc).

So... for an established team of rock-star developers? I'd guess about 4 people (2 for backend, one for ios, one for android) working together would have a pretty mediocre social network going in about 3 months. So, we'll say 12 man-months, given perfect expertise in all subject matters from all developers...

...for a prototype. Start multiplying that estimate by scary scaling factors if
(1) you don't have super experienced developers. This is going to blow your estimate up. It will also hurt your ability to re-estimate in the middle of the project, which is even more important.
(2) the team doesn't already exist.
(3) you need it to be "production ready". That said, basically all startups cheat and launch as soon as code compiles (this is an exaggeration, but you know what I mean)
(4) how programmer of me to forget: documentation!

FWIW, this is coming from an agile/scrum background. YMMV with other methodologies. Waterfall will probably get your social network going in about 10 years.

e: and I should clarify that you cannot discard the scaling factors. You estimate what the best case would be, hope your estimate is remotely on the money, and then try to control for all the stuff you can't control (team makeup, inherited code, whatever it is). Or in another words, even if I estimate 12 man months as the best case, 12 man months is never, ever, ever going to happen. Maybe 36 at best. Or 60. Or 90.
 
Top Bottom