• 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

robin2

Member

[...]
I'd recommend passing along an instance of TerrainGradient to the generateVoxelColor method.

The bolded is what i ended up doing:
Code:
	public static TerrainGradient classic = new TerrainGradient(210, 185, 175, 70, 120, 25, 64);
	public static TerrainGradient mountain = new TerrainGradient(245, 240, 235, 45, 40, 35, 64);
	
	private static class TerrainGradient {
		float Ra;
		float Rb;
		float Ga;
		float Gb;
		float Ba;
		float Bb;
		
		private TerrainGradient(float Rmax, float Gmax, float Bmax, float Rmin, float Gmin, float Bmin, float maxTerrainHeight) {
			this.Ra = (Rmax - Rmin) / (maxTerrainHeight - 0);
			this.Rb = Rmax - (this.Ra * maxTerrainHeight);
			this.Ga = (Gmax - Gmin) / (maxTerrainHeight - 0);
			this.Gb = Gmax - (this.Ga * maxTerrainHeight);
			this.Ba = (Bmax - Bmin) / (maxTerrainHeight - 0);
			this.Bb = Bmax - (this.Ba * maxTerrainHeight);
		}	
	}
	
	public static float generateVoxelColor(TerrainGradient gradient, float voxelYCoordinate) {
		return Color.toFloatBits(
					(int)(gradient.Ra * voxelYCoordinate + gradient.Rb),
					(int)(gradient.Ga * voxelYCoordinate + gradient.Gb),
					(int)(gradient.Ba * voxelYCoordinate + gradient.Bb),
					(int)255
				);
	}

result:
mtnkzk.png
 

JeTmAn81

Member
Regex is super powerful.

When I was presenting my own app and a user wanted to search for something specific I told him to just type regex into the search field. Apparently they didn't think this was a very good solution even if it's the best solution.

Telling an end user to use regular expressions is a terrible idea. Regex can be confusing to developers, let alone the average user.
 

Makai

Member
That's just bastardizing it into a classic business style. Points are just a means of tracking velocity so you don't overload and overcommit, you aren't trying to optimize them.

And you should be tracking longer meetings and refactoring (whether anyone wants to do that though...)
This is it. At retro, they showed a graph of our velocity over time. Somebody said that velocity is not a measure of productivity, then the CTO said "good point. We need to find ways to increase our velocity."
 

Slavik81

Member
Passed here just to comment that I'm porting Qt5 for an embedded device and the compilation process already surpassed 1,5 hour...
Fuck...Stucked at work 4:00 a.m
:(
Ideally you would cross-compile on a workstation rather than compiling directly on the device. It takes maybe an hour on a desktop.

This is it. At retro, they showed a graph of our velocity over time. Somebody said that velocity is not a measure of productivity, then the CTO said "good point. We need to find ways to increase our velocity."
You can always increase velocity by assigning larger point values to your stories. :)
 

Milchjon

Member
I take a lot of notes simply using the Windows NotePad and would love to replace it with something similarly lightweight, but capable of Markdown.

Any tips for Win10?
 
I take a lot of notes simply using the Windows NotePad and would love to replace it with something similarly lightweight, but capable of Markdown.

Any tips for Win10?

Sublime Text is a fairly sophisticated text editor, but it's super fast. Has some nice Markdown plugins. That's what I use for Markdown files. Notepad++ might be good as well.
 

Skinpop

Member
I need an algorithm to trace the resulting outline of axis aligned rectangles that are either adjacent or overlap. I guess another way to put it is that I want to merge several adjacent or overlapping rectangles into a single polygon while removing duplicate and interior points.

The approach I have in mind:
test each edge against every edge extended as a line. Split edges at intersections.
Now I choose some point then walk the edge clockwise. If I run into a point with multiple edges, I always choose the edge that is moset "outward". When I'm back at the first point I'm done.

I think this should work but maybe I'm missing something or there's a more efficient way to do it?
 

empyrean

Member
Bit of advice people if I can be so bold.

My girlfriend is currently working in the USA (we are both firm the U.K.) and next year I might potentially go out and live with her out there and work there too.

Currently I have 3 years experience as a developer (c# and asp.net) but no degree. I was thinking whilst I have the time I might get Microsoft certified (mcsd) as I thought that may increase my chances of finding work in USA. Is it worth my time and effort? Do you think I will struggle to find work without a degree and only 3 years developer experience (I've developed software for a lot longer just only professionally for last 3 years, worked in It my whole career so far).

Any input appreciated.
 

Sesuadra

Unconfirmed Member
Hey you all. My life might change big time and I might get into a 2 year course here in Germany after which I would be "Informatiker anwendungsentwicklung" or in English I'll be certified for application development..including Microsoft certificates.
Now humble bundle has this ebook bundle. https://www.humblebundle.com/books/...b4a6381b04d48e7b8b456a&utm_content=cta_button

Are those books any good, especially for someone starting with programming and who wants to get a good look into different languages? I know the course will focus on C# and there is no book about that in the bundle. But still, I'm interested.
 

Koren

Member
Sublime Text is a fairly sophisticated text editor, but it's super fast. Has some nice Markdown plugins. That's what I use for Markdown files. Notepad++ might be good as well.
I really like Notepad++ (well, I really like Scite, and Notepad++ is mostly a variation), it's a good editor for anything (including Markdown), but I understood he wanted a notepad with the capability of portable, light text formatting. Notepad++ won't render the result itself...

I would have thought he was after something like writemonkey (well, this one is a bit special in that it was designed to run fullscreen so you're not distracted with anything)

The approach I have in mind:
test each edge against every edge extended as a line. Split edges at intersections.
Now I choose some point then walk the edge clockwise. If I run into a point with multiple edges, I always choose the edge that is moset "outward". When I'm back at the first point I'm done.

I think this should work but maybe I'm missing something or there's a more efficient way to do it?
I would compute intersections and do a modified Graham scan, which is, if I'm not mistaken, what you're doing, so I think that's right. Pretty sure I've looked for better solutions in the past and found nothing more convincing...
 

Koren

Member
Are those books any good, especially for someone starting with programming and who wants to get a good look into different languages?
There's plently of free quality stuff (also obviously great books for a couple dozen bucks, if you're interested in a specific subject).

I'd be cautious with these kind of bundles, but at the same time, it's cheap... so even if it's bad, you won't be broke.

I'd do the opposite, though: decide on what I want to learn, look for interesting websites/books on the subject, then try to find interesting offers for the most expensive ones...
 

JeTmAn81

Member
Software dev and general CS knowledge is available for free on almost any subject these days. I'd check out Khan Academy and Coursera if you're interested in learning. Maybe buy some books after you've taken courses that make sense to you.
 

MikeRahl

Member
I need an algorithm to trace the resulting outline of axis aligned rectangles that are either adjacent or overlap. I guess another way to put it is that I want to merge several adjacent or overlapping rectangles into a single polygon while removing duplicate and interior points.

The approach I have in mind:
test each edge against every edge extended as a line. Split edges at intersections.
Now I choose some point then walk the edge clockwise. If I run into a point with multiple edges, I always choose the edge that is moset "outward". When I'm back at the first point I'm done.

I think this should work but maybe I'm missing something or there's a more efficient way to do it?

I literally am working on this at work.

http://stackoverflow.com/a/19475433/337656


Don't know how you are storing your points but I have a list of 3d points (mine aren't always going to be a rectangle).

These are the steps I followed.

1.) Create 2 lists of points that include the original points and all intersected points in the order you traverse them (CCW or CW)

2.) Start at the bottom left point and add to a master list until you get to a point that is shared.

3.) Determine if you stay on your current list, or swap to the next one and repeat from step 1.

4.) You reach your starting point with a complex shape.
 

Skinpop

Member
Thanks! I'm gonna try implement it now. Are there any advantages/disadvantages to adding one shape at a time instead of doing it all at once? I'm thinking that might reduce the number of intersection tests in my case.
 

Koren

Member
1.) Create 2 lists of points that include the original points and all intersected points in the order you traverse them (CCW or CW)
Out of curiosity, what algorithm do you use to compute efficiently the intersections? Bentley-Ottman?

It's slightly easier with axes-aligned rectangles, even if the algorithm is mostly the same...

And you're doing this in 3D? Your points are coplanar, or how do you handle points out of the plane?
 

Koren

Member
Thanks! I'm gonna try and implement it now. Are there any advantages/disadvantages to adding one shape at a time instead of doing it all at once? I'm thinking that might reduce the number of intersection tests in my case.
Pretty sure it'll be quicker to do everything at once, since there's log(n) complexity involved, unless you're doing something clever with your set (prior knowledge of what touch what)
 

MikeRahl

Member
Out of curiosity, what algorithm do you use to compute efficiently the intersections? Bentley-Ottman?

It's slightly easier with axes-aligned rectangles, even if the algorithm is mostly the same...

And you're doing this in 3D? Your points are coplanar, or how do you handle points out of the plane?

Not yet using a known alogoritm! Will have to look into Bentley-Ottman.

Pretty much just iterate through each all points creating vectors and then calculating the intersection points of the vectors and then making sure that the calculated point lines on the line segment (prevents false positives on shapes with more than 4 points).

I am doing this in 3d. The project involves welding things together, and constructing a 3d object, so I need the normal of the 'face' as well and so each 2d 'face' I am working with is actually defined by a plane.

When building up there are really 3 choices, the faces lie on the same plane so I need to union them together, they intersect and so I need to subtract one from another or they are completely disjoint so I need to keep both of them.
 

Koren

Member
Pretty much just iterate through each all points creating vectors and then calculating the intersection points of the vectors and then making sure that the calculated point lines on the line segment (prevents false positives on shapes with more than 4 points).
Isn't this O(n²)?

Anyway, thanks for the details...
 

MikeRahl

Member
Yep.

First iteration of the code and it really doesn't have to be super fast.

For the most practical uses n^2 it's going to be 16 (4^2) and I am only combining 3 rectangular faces.

One benefit of internal projects.
 

Skinpop

Member
well this was a bit more involved than I had anticipated but it seems to be working. Since my rects are axis aligned choosing the next edge can easily be optimized but is there a trick to doing it effectively when dealing with arbitrary edges and 3d? I'm guessing just checking dot of right vector and the edge is the standard approach?
 

Sesuadra

Unconfirmed Member
thanks for the answers. :D the 2 year long class will focus on C#, so I'll save my money and look around for online sources and a book about that.

Edit: columbia university has a free C# course on coursera..I'll enroll in that.
 

NetMapel

Guilty White Male Mods Gave Me This Tag
All you programmers pro out there, let me ask for some experience. Have you ever rolled out a tool or so for your company that definitely made the work process better for all the other colleagues. Then, you tried to get them to use it and there will be some who will stubbornly refuse? The tool in question is extremely user friendly and cuts down on many manual method in which some work is done. Now, with a click of a button, it is all done. It doesn't get any easier than that. Why do some people refuse to use when other colleagues have used it to great satisfaction and success? Do you ever feel like crap like you are not trusted by those who refuse to use your tool? Right now I am feeling pretty down about it because it makes me wonder if those people maybe don't trust my tool, and by extension, my own skill/value/worth.

To be more precise, I work in a small company so it is really just one person who is refusing to use my tool even after I showed him how and asked for his opinion. Straight up still won't use it.
 
All you programmers pro out there, let me ask for some experience. Have you ever rolled out a tool or so for your company that definitely made the work process better for all the other colleagues. Then, you tried to get them to use it and there will be some who will stubbornly refuse? The tool in question is extremely user friendly and cuts down on many manual method in which some work is done. Now, with a click of a button, it is all done. It doesn't get any easier than that. Why do some people refuse to use when other colleagues have used it to great satisfaction and success? Do you ever feel like crap like you are not trusted by those who refuse to use your tool? Right now I am feeling pretty down about it because it makes me wonder if those people maybe don't trust my tool, and by extension, my own skill/value/worth.

To be more precise, I work in a small company so it is really just one person who is refusing to use my tool even after I showed him how and asked for his opinion. Straight up still won't use it.

My goal in life when I created tools was to make my life easier. Other people could or could not use it, that's on them, but it was really all about me. Is my life easier? Then I'm satisfied.

Now, if it turns out that your colleague not using the tool is actually making your life harder, then beat him or her with the nearest blunt object. That's my recommendation. Use violence to beat them into submission.




(Do not actually use violence.)
 

NetMapel

Guilty White Male Mods Gave Me This Tag
My goal in life when I created tools was to make my life easier. Other people could or could not use it, that's on them, but it was really all about me. Is my life easier? Then I'm satisfied.

Now, if it turns out that your colleague not using the tool is actually making your life harder, then beat him or her with the nearest blunt object. That's my recommendation. Use violence to beat them into submission.




(Do not actually use violence.)
Yeah true I understand. The problem is, it does affect other people's work. Basically, people in my company do their work and then send it to a server farm to get processed. The farm generally prioritize each job on a first come first serve basis if the job's "priority" value are the same. If a job comes into the farm at a higher priority, then it pauses all previous jobs to process the new higher priority job. Generally this is fine for emergency stuff but that doesn't happen often. Previous to the launch of my tool, colleagues will have to manually input in various stuff in order for the server to start processing the job. Well, I made a tool that automates that process so with a click of s button, your job gets sent to the farm for processing without having to manually put in other data. I have set my tool so that when it submits a job to the farm, it doesn't have the max priority setting because I want to leave room for emergency jobs like I've mentioned before. Well, this guy not only refuse to use my tool, he also always submit his job at max priority so everybody else's work gets paused when he submits his job. How selfish and rude do you have to be to always think your job is the most important and deserves all that priority? I've tried explaining this to him before too and he won't listen :(
 

JesseZao

Member
All you programmers pro out there, let me ask for some experience. Have you ever rolled out a tool or so for your company that definitely made the work process better for all the other colleagues. Then, you tried to get them to use it and there will be some who will stubbornly refuse? The tool in question is extremely user friendly and cuts down on many manual method in which some work is done. Now, with a click of a button, it is all done. It doesn't get any easier than that. Why do some people refuse to use when other colleagues have used it to great satisfaction and success? Do you ever feel like crap like you are not trusted by those who refuse to use your tool? Right now I am feeling pretty down about it because it makes me wonder if those people maybe don't trust my tool, and by extension, my own skill/value/worth.

To be more precise, I work in a small company so it is really just one person who is refusing to use my tool even after I showed him how and asked for his opinion. Straight up still won't use it.

I've dealt with that and it's incredibly annoying. It's a sure-fire way to get me to put any other pending projects for then on my back burner. It's not a grudge thing, I just want to spend my development time where I'll have the biggest impact.
 

Makai

Member
All you programmers pro out there, let me ask for some experience. Have you ever rolled out a tool or so for your company that definitely made the work process better for all the other colleagues. Then, you tried to get them to use it and there will be some who will stubbornly refuse? The tool in question is extremely user friendly and cuts down on many manual method in which some work is done. Now, with a click of a button, it is all done. It doesn't get any easier than that. Why do some people refuse to use when other colleagues have used it to great satisfaction and success? Do you ever feel like crap like you are not trusted by those who refuse to use your tool? Right now I am feeling pretty down about it because it makes me wonder if those people maybe don't trust my tool, and by extension, my own skill/value/worth.

To be more precise, I work in a small company so it is really just one person who is refusing to use my tool even after I showed him how and asked for his opinion. Straight up still won't use it.
I made a tool that let project managers specify project requirements and automaticaly generate all code architecture including unit tests. This was right before we all got laid off in a hostile takeover.
 

NetMapel

Guilty White Male Mods Gave Me This Tag
I made a tool that let project managers specify project requirements and automaticaly generate all code architecture including unit tests. This was right before we all got laid off in a hostile takeover.
:O sorry to hear that. I promise though that this tool won't be killing jobs. It is a very standard tool used in my industry and the only reason my current company doesn't have it is the lack of expertise. It is a small company and people are just so used to doing this manually. However, go to any other companies within my industry and this part is automated like what I've just implemented. The real bulk of the work that we do isn't this particular step, hence why I am in favour of automating it so we can concentrate on the real work instead. All the big work is done and then sent to the server farm for processing. I am just making the submission part easier which is only good for us employees.
 

Grakl

Member
Hey yall, friend of mine says don't use LPTHW b/c 2.7 is outdated and should just jump into a tutorial with python v 3.x. Is this good advice? If so, any recommended tutorials?
 

Makai

Member
Hey yall, friend of mine says don't use LPTHW b/c 2.7 is outdated and should just jump into a tutorial with python v 3.x. Is this good advice? If so, any recommended tutorials?
Are you new to programming? Just about anything is good when you're starting out.
 

Koren

Member
Hey yall, friend of mine says don't use LPTHW b/c 2.7 is outdated and should just jump into a tutorial with python v 3.x. Is this good advice? If so, any recommended tutorials?
As I said a couple days ago (and before), I think LPTHW is just bad... but that may be just me (well, not just me, apparently). And yes, I'm talking about *beginner* ressources. I'd say the official tutorial is better, but there may be better ressources.

As for Python 3k of Python 2, that doesn't really matter. The differences, especially at first, are few and subtle. I'd be leaning towards 3k (print as a function, // for integer division, saner input, range is an iterator), but you'll be fine with 2 too.


Somehow, I may go with the easiest install! Pyzo (3k) is nice on Windows. Python x,y (2) is nice too.


HI haven't the slightest what this means. How do I find this "environment"? I'm running Home Assistant on a Raspberry Pi 3 and would like to control my various media players, but have been stuck. Any help would be greatly appreciated
You probably can just type "pip install firetv" in a shell (if you have both Python and Python3k installed, there may be issues, but if both are installed, 2 is probably the default)

Which OS do you run on your raspi?

(Beware, pip is handy, but I don't trust this system at all, I think it's a huge security hole...
 
You probably can just type "pip install firetv" in a shell (if you have both Python and Python3k installed, there may be issues, but if both are installed, 2 is probably the default)

Which OS do you run on your raspi?

(Beware, pip is handy, but I don't trust this system at all, I think it's a huge security hole...

Thanks for the response. I have Python 2.7. Pretty sure my OS is just Raspbian. I'm a complete noob with all this stuff, unfortunately. What exactly is a shell and how do I find it? Thanks again.
 

Makai

Member

Makai

Member
If you don't understand the return type there, it's like

Code:
enum Result
{
    Value(Vec<u8>),
    Error(std:io:Error)
}

Extra parameters can be stored in each case. It lets you know transparently that it can error and you handle the error when you match on the result.
 

Gattsu25

Banned
Thanks for the response. I have Python 2.7. Pretty sure my OS is just Raspbian. I'm a complete noob with all this stuff, unfortunately. What exactly is a shell and how do I find it? Thanks again.

The shell is the DOS-like* command prompt*. It's one of the cores of a good operating system.

I haven't used raspbian so I'm going off of google images...so forgive me if this is off:
c8ctGVc.png


You'll want to open up the Terminal from this image. Looks like it is located in Menu --> Accessories --> Terminal

I'm assuming you used this to confirm your python version (using the python --version command)

Just paste that command in the terminal.
 
The shell is the DOS-like* command prompt*. It's one of the cores of a good operating system.

I haven't used raspbian so I'm going off of google images...so forgive me if this is off:
c8ctGVc.png


You'll want to open up the Terminal from this image. Looks like it is located in Menu --> Accessories --> Terminal

I'm assuming you used this to confirm your python version (using the python --version command)

Just paste that command in the terminal.

Thanks, man. Actually got everything installed now. Still catching some errors, but that's another story lol.

Edit-

And now I'm fine &#128513;. Thanks, once more, y'all..
 

Koren

Member
Thanks for the response. I have Python 2.7. Pretty sure my OS is just Raspbian. I'm a complete noob with all this stuff, unfortunately. What exactly is a shell and how do I find it? Thanks again.
Shell = command line (in a terminal), where you can enter commands to install things.

Are you using a graphical interface?
 

gaugebozo

Member
I'm applying for jobs, and just received a test that I have to send back in a few days where I need to do a paper and pencil calculation of probability, then a computer simulation as a check. This isn't exactly a programming job, but more math that requires programming. I've never got to this stage in interviews before, so I have some questions:

1). I just send source code, right?
2). Is there a programming style for these sorts of questions? This is basically a Project Euler level question and doesn't require the full machinery of C++. Should I be putting in consistency checks, etc.?
 

Koren

Member
1). I just send source code, right?
It's C++? Only standard lib includes?

If so, I'd say yes, although I may add a compiling command as a comment at the beginning of the file.

I'd also specify the version (11, 14) if you use newer functions.

2). Is there a programming style for these sorts of questions? This is basically a Project Euler level question and doesn't require the full machinery of C++. Should I be putting in consistency checks, etc.?
I'd say that it depends on which kind of job you're applying for. If it's for software development, I'd say style and possibly tests plays a role. If computing is a tool in the job, just a sane algorithm will probably be sufficient.
 

Somnid

Member
https://www.reddit.com/r/rust/comme...jpeg_decoder_in_rust_part_2/d6obz7r?context=2

Code:
fn file_to_bytes(path: &Path) -> Result<Vec<u8>, std::io::Error> {
    File::open(path).and_then(|mut file| {
        let mut bytes = Vec::new();
        try!(file.read_to_end(&mut bytes));
        Ok(bytes)
    })
}

Every time I think about picking up Rust I see code like this and get turned off. This makes enterprise Java look good.

I think if they choose not to go with python casing, and instead of the C style namespacing operator "::" for a simple "." it would look a lot better, it just throws up a lot of symbols which I've generally argued is bad language design, especially for a novice of the language because it's hard to understand new operators and not easy to lookup.

Note that just the nature of Rust means you'll have to think about things differently. There's no nulls and no exceptions, you must deal with them where they happen. As such the return type uses the Result monad to describe the end state (error, or a result which needs unwrapping). If you understand these patterns it becomes very easy to understand this code, and this pattern is used all over the place.

https://doc.rust-lang.org/book/error-handling.html is a good start that explains the whole idea before introducing a bunch of magic shortcuts.
 
Top Bottom