[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 33
File: 1422385664777_6.jpg (438 KB, 2500x1000) Image search: [Google]
1422385664777_6.jpg
438 KB, 2500x1000
Old /dpt/ at >>53537602

What are you working on?
I'm pretending that I know how to write anything more complex than fibonacci's numbers, and that I use my text editor for anything other than ricing my window manager and the rest of the programs to match their colors
>>
Anyone here know html?
>>
nth for
>>53540729

Any germans/nordics here? What layout are you using to code
>>
>>53541999
i use the standard swedish layout but with DESIGNATED macro keys on the side for curly braces
>>
>>53541965
> html
has nothing to do with programing faggot
>>
File: C.png (5 KB, 376x214) Image search: [Google]
C.png
5 KB, 376x214
Isn't C truly a language made by God himself?
>>
>>53541965
>>>/g/wdg
>>
>>53542066
yeah wathever man.
give me a shot.
[email protected]

I don't give a fuck if you're learning, I like to talk with random anons.
>>
Is this a meme or something?
>>
>>53542143
what happens if mode is 1 or 2?
>>
>>53542143
what le fuck

I mean I get it but I really hope no one writes code like this
>>
>>53542182
freshman literature.
>>
>>53542189
bypasses the gloop check. switch cases are labels and switch statement is a goto. (or at least you can interpret it like that)
>>
File: reddit-discarded.png (734 KB, 800x800) Image search: [Google]
reddit-discarded.png
734 KB, 800x800
>>53542191
>le
>>
>>53542143
https://en.wikipedia.org/wiki/Duff's_device
>>
>>53542143
modern compilers will have an easier time dealing with the straightforward version
>>
>>53542191
>not ironically using le
le ebin troll xdd
>>
>>53542211
Pretty cool. Now, with compilers unrolling loops for us it's irrelevant though.
>>
>>53542259
now C is obsolete.
>>
I have an enum, and I want to create a Dictionary, with each value of the enum being a key to a double initialized to 1.

Do all four variations accomplish this? Is there some subtle difference between them I need to be aware of? What is the point of Enum.ToObject if I can just cast?
var eValues = Enum.GetValues(typeof(FooEnum));
Dictionary<FooEnum, double> bar;

// 1.
bar = new Dictionary<FooEnum, double>(eValues.Length);
foreach (var o in eValues) {
FooEnum e = (FooEnum)Enum.GetObject(typeof(FooEnum), o);
bar.Add(e, 1.0);
}

// 2.
bar = new Dictionary<FooEnum, double>(eValues.Length);
foreach (var o in eValues) {
FooEnum e = (FooEnum)o;
bar.Add(e, 1.0);
}

// 3.
bar = new Dictionary<FooEnum, double>(eValues.Length);
foreach (FooEnum e in eValues) {
bar.Add(e, 1.0);
}

// 4. (Linq)
bar = eValues.Cast<FooEnum>().ToDictionary(e => e, e => 1.0);
>>
File: CWgV0ruUsAAcUD7.jpg large.jpg (155 KB, 1024x1024) Image search: [Google]
CWgV0ruUsAAcUD7.jpg large.jpg
155 KB, 1024x1024
>2016
>people still use C
>people still think they'll be using more Haskell in a near future
>>
File: hakase2.jpg (57 KB, 544x708) Image search: [Google]
hakase2.jpg
57 KB, 544x708
>>53542567
>effective XML
>>
>>53542567
C++ and java are the only sensible choices for most applications
>>
>>53541936
Playing with the PCRE library in C.

'pretty fun
>>
>>53542567

Life would be better if the computer had never been invented.
>>
>We will never, ever have a /dpt/ that isn't just people that don't code calling languages they have never used shit and redundant
>>
File: dont-do-that.jpg (79 KB, 698x699) Image search: [Google]
dont-do-that.jpg
79 KB, 698x699
>>53542638
>C++ and java
>>
>>53542675
/dpt/ is SHIT
>>
>>53542698
>language elitism
you know that provided you haven't built a horrible chimera, it really doesn't matter too much what language you're using

fuck mate some scripts are best just to run them in basic for chrissake
>>
>>53542675
python is objectively shit
>>
>>53542143
int gloop_ret = 0;

if(!mode) {
gloop_ret = 1;
}

if(gloop_ret || (mode == 1)) {
result = afr();

} else {
result = barf();

}


You could argue that there should be another check in case the mode isn't 2 but the final else still triggers.
I could account for that, but the switch doesn't even have a default so I really don't give a shit.
>>
>>53542782
>gloop_ret = 1;
Shit, I dun goof'd

int gloop_ret = 0;

if(!mode) {
gloop_ret = gloop(a, b);
}

if(gloop_ret || (mode == 1)) {
result = afr();

} else {
result = barf();

}
>>
>>53542143
if(mode == 0) {
return gloop(a, b) ? arfle(a, b) : barfle(a, b);
}

if(mode == 1) {
return arfle(a, b);
}

if(mode == 2) {
return barfle(a, b);
}

return result;
>>
>>53542930
You could just use a switch like a sane person
>all this code duplication
>>
>>53542947
switches can get very uglily compiled

the compiler will figure it out
>>
>>53541936
Case statements and dynamic reboot sequences in powershell.

Fuckin yay...
>>
>>53542947

Or use >>53542830
No need for a switch at all.

It only requires one more compare, but it's a 0 check so it's relatively cheap.
I've also prioritised the check for gloop_ret so if you've had to make that function call you can short-circuit with the second 0-check (well half the time).

If gloop_ret is more likely to be 0 then simply reorder the conditions to be (!gloop_ret || mode == 2) res = barf(); else res = arf();

Also it should just return from the conditions, not set result and then return after, although this is probably optimised out anyway.
>>
>>53543103
it makes the branching much less predictable
>>
File: 51BePH76gJL.jpg (38 KB, 500x500) Image search: [Google]
51BePH76gJL.jpg
38 KB, 500x500
What's the most optimal way of rendering a textured heightmap in opengl where the textures may be different from tile to tile?

I'm currently splitting my heightmap down into regions and rendering those regions seperately through a VBO, but it's definitely feels slow.
>>
>>53543159
You have 2 possible calls, arfle() or barfle(), so neither method is going to pipeline very well.

In fact if you are concerned with being predictable, then you should call gloop() whether you need the return or not, then make the "switch" constant time for all cases.
>>
Thinking about learning a litttle bit of assembly. Should I learn 32 bit, then move on to 64 bit or just start with 64 bit? Should I use a different architecture, like MIPS? Anyone got some good links?

Thanks anons
>>
Any reason to why this isn't finding my file?

conf = "file.conf"
for root, dirs, files in os.walk('root'):
print "searching", root
if conf in files:
print "found: " + join(root, conf)


It doesn't find my file for some reason, I'm looking to avoid hard coding because this file may exist anywhere.

I'm on Linux if that helps
>>
>>53543451
It's worth mentioning that it doesn't print "searching", or anything for that matter. Doesn't break or print an error message
>>
What else should I add?: http://anonlabs.byethost10.com/
>>
File: Capture.png (54 KB, 649x642) Image search: [Google]
Capture.png
54 KB, 649x642
>>53543451
'root' is not a directory
os.walk("/")
>>
>>53543503
I can't believe that, I re-wrote this code numerous times because I didn't use '\'.

Offhand, do you know how to make it return only the first match?

Because at the moment, its printing several and the only way I know is by breaking it, but if you break it then you can't use the value elsewhere.
>>
>>53543443
32-bit runs on everything anyway. 64-bit is really just 32 with bolts added on, so you'll need 32 to understand 64.

Also MIPS is a world away from x86, not a lot is transferable really, so just learn whatever you think will actually be useful.
Not just in a "this is kinda cool" way, but actually useful. If you are going the micro route, I would suggest PIC over MIPS.

There are educational architectures like SAYEH if you just want to learn the theory but they are pretty useless in the real world.
>>
>>53543443
A lot of universities teach their basic asm course using Patterson and Hennessy's 'Computer Organization and Design: The Hardware/Software Interface', which uses MIPS. MIPS has a very simple instruction set and it would probably be the best place to start just to get used to how registers, etc. work.

If you learn something like the latest intel instruction set you may be introducing yourself to too much complexity and making things harder.
>>
>>53543691
This. You will learn the newfangled instructions when you need them.
>>
>>53543587
string firstmatch = ""
conf = "file.conf"
for root, dirs, files in os.walk('/'):
print "searching", root
if conf in files:
firstmatch = "found: " + join(root, conf)
print(firstmatch)

something like that
>>
>>53543587
Forget this, it's nonsense, break still works perfectly.
>>
>>53543739
>>53543756
Thanks
>>
>>53543205
Using a texture array would be a good place to start. It would allow you to coalesce all the geometry together, and more importantly save on expensive texture binds.
>>
>>53543756
>
string firstmatch
>>
>>53543802
i don't know python ok
>>
>>53543691
>>53543742
You know you can use x86 without using EVERY instruction, right?
>>
>>53543786
you probably want to break after >>53543756 otherwise os.walk will continue iterating through each file in the system

>>53543838
fair enough
>>
>>53543864
yeah idk why i forgot to put a break there
>>
>>53543451
>>53543473
Does the directory exist?
>>
File: 8243834651_d0732cab05_b.jpg (246 KB, 1024x681) Image search: [Google]
8243834651_d0732cab05_b.jpg
246 KB, 1024x681
Hey /g/

I started taking a C++ course this semester. It's basically been the professor lecturing by reading off these powerpoints that are basically notes for the reading assignments.

Every week we have this lil quiz online that asks us about simple concepts that were in the notes/reading assignment. Before every class meeting we have to turn in some homework that is writing this small program in microsoft visual studio, and then including a screenshot of our program working and our code.

So after the professor reads his notes to everyone we take a break and then start our "lab" portion of the class which has been strictly programming the mindstorms lego robot using Bricx and doing some NXC codes so that we can get our lego robot to do something like follow a line of tape on the floor.

The thing about this is that the professor gives us little direction and we basically have to figure everything out on our own, including writing the programs for the homework.


>TLDR

How do I teach myself other than reading a book and being confused in class every day?

I'm not a computer engineer/computer science but this is a required course for my major that involves C++ but we do little to no actual C++ practice in class. Even the professor says he doesnt like the way the course is being implemented.
>>
>>53542017

thanks for your input. I figured I'm so used to my current layout anyway, I'll just change the curleys and \.
>>
>>53543943
we have a class similar to that
>>
>>53544008
ok
>>
>>53543943
youtube
>>
File: opengl.webm (100 KB, 800x600) Image search: [Google]
opengl.webm
100 KB, 800x600
I learned just enough math to generate circles programatically!

How does one go about making a solid sphere in opengl?
I'm not asking how to do it, just, what kind of GL primitive would I use to make a sphere?
>>
hey yo pals I ran into a little trouble making a small roguelike game

I'm trying to make the little dude walk around the room but he just disappears when I hit any key

here's the movement code
[script]void Move(char direction)
{
int posX = getPlayerPosX();
int posY = getPlayerPosY();

mvaddch(posY, posX, '.');

if(direction == KEY_UP)
mvaddch(posY - 1, posX, '@');
if(direction == KEY_DOWN)
mvaddch(posY + 1, posX, '@');
if(direction == KEY_LEFT)
mvaddch(posY, posX - 1, '@');
if(direction == KEY_RIGHT)
mvaddch(posY, posX + 1, '@');
}[/script]
I'm using ncurses
and here are the getPosition functions
[script]
int getPlayerPosX()
{
int y;
int x;
char pl;

for(y = 0; y < 40; y++)
{
for(x = 0; x < 60; x++)
{
pl = mvinch(y, x);
if(pl == '@')
return x;
}
}
}
[/script]
help pls senpai
>>
>>53544052
any specific channels?
We are doing Looping this chapter and then functions for next week
>>
>>53544072
yo forgot it was code instead of script
>>
>>53543851
Of course, but it's still a bit more overhead. It kinda depends on what >>53543443 wants to learn. IMO reading Computer Organisation and Design and learning MIPS would be better if he wants to learn all of the details of how processors work at a low level, while using the assembly to facilitate that exploration. In addition to less instructions, it also has fixed length instructions, which may make things easier to grok.

If he just wants to learn some random assembly language for the hell of it, it doesn't really matter what he chooses.
>>
Where can i fucking learn to code?
I want to learn python first, as everyone seems to advice around here, but codecademy sucks so many balls i can't even start to count them.

How can I learn the proper way, not just memorizing shit babby stuff like codecademy drives you to do?
>>
>>53544058
Spheres can be made in many different ways
Whether triangle/quad/polygon is best depends on the type of sphere
>>
>>53544165
You learn to code by writing code.

There's not really more to it.
>>
>>53544176
I need basics, but not the basics assholecademy gives you. There's got to be another way, I don't need easier, just better.
>>
File: stufftodo.png (305 KB, 1920x1080) Image search: [Google]
stufftodo.png
305 KB, 1920x1080
>>53544194
grab a book and do all this nerd
>>
>>53544293
Any books you would recommend for total beginners? That roll chart seems interesting.
>>
File: output.webm (3 MB, 640x480) Image search: [Google]
output.webm
3 MB, 640x480
Do you like my cube? :3
>>
Can some emacs/regex guru tell me why this wouldn't match?
>>
>>53544321
I like you. :3
>>
>>53544321
>No texture
>No shading
3/10. I'll bump it up to a 4 if you used glsl.
>>
>>53544318
Not him, but go to a thrift shop and pick up any c++ book. You'll be fine. It builds character
>>
File: output.webm (3 MB, 640x480) Image search: [Google]
output.webm
3 MB, 640x480
>>53544340
does glBegin/glEnd count?
>>
>>53544399
>Primitives.
You cherish that 3. You earned it.
>>
I'm looking to pull the /g/ or /sp/ or /tv/ component from a 4chan link in python. I know the logic is something like:
*find .org/
*continue until you reach /t
But I'm stuck as to how to do it. Any suggestions?
>>
>>53544366
OK DAD
>>
>>53544366
But wouldn't c++ be a little bit advanced for me? I know it can be a little harsh for total beginners to learn it from scratch. I'm taking your advice anyway, but what about pdf python books? Do you know any that's worth the read?
>>
>>53544399
Seriously though, learn shaders anon. glbegin/end are deprecated.
>>
File: HelpResource.ashx.png (906 B, 304x45) Image search: [Google]
HelpResource.ashx.png
906 B, 304x45
currently looking into making a trackbar that has two sliders. about to give up though.
>>
>>53544473
>But wouldn't c++ be a little bit advanced for me?
I learned it when I was 8 years old
It'll be a little tough at points, but at least you won't end up like the python and js babies I have to clean up after everyday
>>53544473
>I'm taking your advice anyway, but what about pdf python books? Do you know any that's worth the read?
Python is one of the worst first language to learn. "Python the Hard Way" by Zed Shaw is a pretty good book to use if you have some experience in another language, and it's free online
>>
>>53544525
>I learned it when I was 8 years old

Calm down Stroustrup.
>>
>>53544525
>I learned it when I was 8 years old
Is this true? If so, how?
>Python is one of the worst first language to learn
Why is this? Could you give some reasons with examples, please?
>>
>>53544525
>Savants on 4chan

I want to believe.
>>
>>53544481
I'm getting there, anon.
i'm barely at the part of the opengl book that discusses linear algebra
>>
>>53544565
>Is this true?

Without a doubt, it is utterly and completely false.
>>
>>53544565
>Is this true? If so, how?
yes
>be 8
>have computer
>get c++ book for christmas
>read it
>learn c++

>Why is this? Could you give some reasons with examples, please?
Call me old fashioned but I think everyone should start out with a low level, strongly typed language, because it will teach you some things about computers that if you don't know will lead you to write terrible code and because for beginners, weak typing can encourage some bad habits, habits I have made a career out of correcting. Plus working with a compiler will put some hair on your chest rather than an interpreter.

It won't matter if you just want to do it in your moms basement, but if you ever get out in the field and have to work with a million-line Java project, with 100's of people (mostly morons) working on it, you'll be a lot better off and your coworkers won't hate you
>>
File: yup.jpg (66 KB, 460x598) Image search: [Google]
yup.jpg
66 KB, 460x598
>>53544293
bored anyway.
rolling
>>
>>53544604
>>53544635
>implying it's impossible to learn programming as a child
goddamn I was writing hello world and stupid text adventure games, not a fucking 3d flight simulator. I figured most of you would have started around 8-12.
>>
>>53544701

I started yesterday.
>>
>>53544604
Learning resources were not so great as little as 10 years ago.

Either you're underage or you're lying.
>>
File: basicgames.jpg (100 KB, 304x400) Image search: [Google]
basicgames.jpg
100 KB, 304x400
>>53544742
>Learning resources were not so great as little as 10 years ago.
>implying
>>
>>53544701
I didn't have a computer in my house until I was 15, didn't start programming until almost 17 (schools didn't fucking have any relevant courses until final 2 years of high school).

I'd be much better if I'd started earlier, but it's not like I would have learned "faster" if I started earlier.

>>53544756
As in they were harder to come by, or even compare. The internet is a wonderful thing as far as user reviews go.
You could have been reading an utter piece of shit book, you'd never know until you'd finished it and found something better as a complete beginner.
>>
>>53544701
I 'started' around 12 but it took me a few years to be able to actually program at a reasonable level
>>
>>53544793
>The internet is a wonderful thing

It sure is. Where else would you get your weird fetish pornography?
>>
>>53544829
Well yeah, of course. Same here. I'm just saying it's not hard to start doing simple stuff and get in the programming mind set as a child without being a fucking savant
>>
>>53544420
print 'https://boards.4chan.org/g/thread/53541936'.split('/')[3]
>>
>>53544850

Getting into programming is one thing. LEARNING C++ is on another level.
>>
>>53544875
Ah ok, I see what you mean. In that case I still haven't _learned_ c++, I doubt many people have completely, have you seen the size of the spec?
>>
What's a good source for learning about Operating systems?
I couldn't find any courses on coursera.
I'm trying to bridge the gaps in my CS knowledge.
>>
>>53544875
What's so hard about learning C++?
Isn't it basically C with a giant standard library that has 20+ different ways of doing the same mundane shit?
>>
>>53544912
templates

shit the c shills ignorantly gloss over in discussions because they are unable to comprehend its power
>>
>>53544333
Not tying to spam, but I still can't seem to resolve this. Anyone here know emacs? I just want to be done with this regex shit
>>
>>53544952
so basically, C preprocessor abuse?
>>
>>53544912
>Isn't it basically C with a giant standard library that has 20+ different ways of doing the same mundane shit?

It's that and a whole lot more.
>>
>>53544501
it might be helpful to search for "range slider"
>>
best books to learn C and C++?
>>
>>53544984
tempaltes are much more powerfull than preprocessor could ever be. Templates are not only a turing complete functional pattern matching language, but also beautiful code generation tool.

Templates are way more than even generics

With templates i was able to make the prepro generate parser classes on compiletime based of DSL regex syntax (c.f. boost::spirit)

lit('4chan.org/g/thread/') >> *cls('\d') >> any()

you jsut cant do that in any other language
>>
>>53545052
so instead of writing libraries for general usage and generally being in control of what you're calling, you're advocating people write do-all libraries full of templates that generate untold amounts of shitcode just because?
>>
>>53545074
>so instead of writing libraries for general usage and generally being in control of what you're calling,
you are in control‽

>you're advocating people write do-all libraries full of templates
like you impliment heapsort, do you want to write a version for every data type there is? or do you want to cast everything to void* and require the user to pass you a predicate which will cast those void* back to something useful and compare them or basically let compiler do the job of inserting the type name and avoiding dangerous casts

>that generate untold amounts of shitcode just because?
what is -O2
writing templates is THE way to make libraries
>>
File: 1414517442153-0.gif (2 MB, 384x384) Image search: [Google]
1414517442153-0.gif
2 MB, 384x384
Really fucking bored and have been meaning to get around to this for a while
What's a good language to learn for a beginner and what book should I get to go along with it (I know there are plenty of online guides, but I do much better with an actual book in just about everything)
>>
>>53545132
just use void functions
if your user can't write a goddamn callback function, they don't deserve to use your library
>>
>>53544293
pls easy
>>
File: 3.jpg (66 KB, 950x534) Image search: [Google]
3.jpg
66 KB, 950x534
same anon as yesterday:

on the knapsack problem:

an item has a weight, a value and an id.
Now, i want to maximize the profit given a certain maximum weigth. **BUT** i can't have items with the same id.

i mean if an item with the id = 4 has 3 different values, i can only pick the best value from those.

any way to approach this?

i already solved for the normal knapsack 0/1, my solution keeps adding items with the same id...
>>
>>53545172
the point si not about supplying a "callback" its about losing all information about type by forcing castst to shit instead of using generics

but anyway, theres a reason most people dont understand templates
>>
>>53544072
int getPlayerPosX()
...
for(y = 0; y < 40; y++)...

for(x = 0; x < 60; x++)...

Why are you searching for the player instead of storing the position with the rest of the player data? Presumably you have a player struct or class that holds all of the player info, and it should include the player location.

Also, are you verifying that the move location is a valid one before you move there?

what do mvinch and mvaddch do?
>>
>>53545196
* IQuat was supposed to be IPoint3
>>
>>53545014
"range slider" isn't a native winapi control, so it's usless to me. I could make a slider that owner drawn or w/e but it's not worth the time.
>>
File: 2lMztl1.webm (695 KB, 406x720) Image search: [Google]
2lMztl1.webm
695 KB, 406x720
Guys how do I find programmer friends online?
>>
>>53545247
Did he died?
>>
>>53545247
Try craigslist. Post that you're looking to program and chill.
>>
>>53545132
>write a version for every data type there is
jesus fucking christ! have you people EVER worked on a real project?
>>
>>53545132
>writing templates is THE way to make libraries
*that take an hour to compile and have no stable ABI
>>
File: 1450605134471.jpg (93 KB, 640x640) Image search: [Google]
1450605134471.jpg
93 KB, 640x640
Dear /dpt/,

I have this interface in C#
public interface IPoint3 : IEquatable<IPoint3>, IDisposable, INativeObject

which is apparently based of the type
Autodesk.Max.Wrappers.Point3

however Point3 is inaccessible due to its protection level and clicking "Go To Declaration" is only showing me
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyCompany("Autodesk Inc.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCopyright("Copyright (c) Autodesk 2007")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyProduct("ManagedServices")]
[assembly: AssemblyTitle("ManagedServices")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a159632d-a3b4-4f85-8093-93d4ec1d6faa")]
[assembly: TargetFramework(".NETFramework,Version=V4.5", FrameworkDisplayName = ".NET Framework 4.5")]
[assembly: SecurityRules]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]


Does anyone know how I am supposed to create a "new" IPoint3?
The interface doesn't have any constructors or static methods
>>
>>53545276
http://www.inquisitr.com/2433888/disturbing-video-shows-paris-man-fall-to-his-death-after-climbing-tall-statue-during-rave/
>>
>>53545298
>headeronly libs
>ABI
pick one

also if you care about compile time that much google what d pointer and cheshire cat is about
>>
>>53545302
> clicking "Go To Declaration" is only showing me
behold, the crippling results of years IDE use!
>>
>>53545132
>cast everything to void*
In C you do not need casting from or to void *
>>
>>53545219
void * is generics
>>
>>53545336
Well, I already figured the problem is it not being com visible
But that doesn't really help me of course
>>
>>53545357
void qsort (void* base, size_t num, size_t size, int (*compar)(const void*,const void*));

vs

template< class RandomIt, class Compare >
void sort( RandomIt first, RandomIt last, Compare comp );

>>53545378
can you sizeof it? you can a template
>>
>>53545396
Both of these are absolutely unrelated to what I said.

>void qsort (void* base, size_t num, size_t size, int (*compar)(const void*,const void*));
That would actually be more than fine if C had anonymous functions. Now they can only be used as a GCC extension.
>>
>>53545396
Also
>type* name instead of type *name
Opinion discarded, hang yourself.
>>
>>53545396
First one looks neat and perfectly serviceable.
and the callback function is piss easy to write.
int compar(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
>>
>>53545213
For each id, work out which item has the greatest value/weight ratio.

Then, run whatever you used to solve 1/0 but over the list of "best ofs".
>>
>>53545437
>*(int *)a
haha

template <typename T>
int compar(const T& a, const T& b) {
return a < b;
}

handles doubles, floats, ints, string all of it

and for int love we can specialize

template<>
int compar<int>(const int& a, const int& b) {
return a - b;
}

now instead of passign comparators every time i jsut let the compiler write them for me
>>
>>53545302
10/10 would inhale water.
>>
>>53545484
>template <typename T>
>T&
haha
>>
>>53545514
well i hope you can look bisy by sitting and writing all functions and classes over and over instead of getting handed a real task
>>
>>53545470
thanks for the reply anon.
that was my idea initialy, but take this for example:

id---weigth---value
3---3---9
3---1---1
3---2---8
1---2---5
1---3---7
1---1---4
if the maximum weigth was 12 i would chose the items:
3---2---8
1---1---4

how do you find the greatest value/weight ratio here?
(note that item 3 has a value of 9 too and item 1 has a value of 7 witch is gret that 4)
>>
>>53545514
>T&
thats a reference, you C guys dont know that, its like passing by pointer without the dereference overhead
>>
>>53545546
you want to know how I can tell you've never worked with another human being on the same codebase?
>>
>>53545566
What if I purposely do both?
like &array[i] instead of array+i.
>>
>>53545571
enlighten me
i just happend to have coworker using tempaltes to do work all the time. lucky me
>>53545582
nah, its about being able to modify it in the callee
>>
I'm trying to make a pig latin translator in python, because Codecademy's PygLatin section only works properly on words that start with consonants.
Here's what I have so far:
def pyglatin():
original = raw_input("Enter a word: ")
s = original.lower()
vowel = ["a", "e", "i", "o", "u"]
consonant_word = s[1:] + s[0] + 'ay'
vowel_word = s + 'yay'
if len(original) > 0 and original.isalpha() and s[0] = vowel:
print vowel_word
elif if len(original) > 0 and original.isalpha() and s[0] != vowel:
print consonant_word
else:
print 'Input contains a non-alphabetical character.'
pyglatin()
pyglatin()

What needs to change?
>>
>>53545563
Well using that example, value/weight ratios would have done the job perfectly.

It will work better the higher W is in relation to the individual item weights.
It's not exhaustive, and may well not always find the optimal solution, but it's much faster than bruteforcing.

If you had to find the absolute best option, then you could at least sort the permutations somewhat by the ratios so you get a good answer quicker.
The problem there is how do you know you have the best answer until you've finished every possible one, you'd need a threshold like 95% of w minimum or whatever.
>>
best book to learn C and C++?
>>
>I'm pretending that I know how to write anything more complex than fibonacci's numbers, and that I use my text editor for anything other than ricing my window manager and the rest of the programs to match their colors

You get me in so many ways man.
>>
I want to brush up on my algebra/pre-calc before self-learning calculus, what books does /dpt/ recommend?
>>
>>53545676
accelerated C++
>>
>>53545656
Double equals on s[0] = vowel.
>>
I'm 25.

Should I drop out of college(only a freshman), get a full time job, move out, and learn to code so I build my way up.

||

Should I leave work and continue living with the parents while I pursue college and that lined of path. Don't forget to attribute the debt into this category.

I live with my parents in a very small mobile home with 2 other siblings and a dog and I feel like I don't belong. I'm embarrassed really.
>>
>>53545707
Thanks, but something else is wrong. It doesn't run.
>>
>>53545735
Not him, but it helps if you give the error message
>>
>>53545656
if len(original) > 0 and original.isalpha():
if s[0] in vowel:
print vowel
else:
print constant_word
else:
print 'Input contains a non-alphabetical character.'
>>
>>53545566
>its like passing by pointer without the dereference overhead
Nope, wrong
>>
>>53545735
If you are running this as a script you need an
if __name__ == "__main__"

and put your pyglatin function call in that block.
>>
>>53545749
if len(original) > 0 and original.isalpha():
print vowel if s[0] in vowel else constant_word
else:
print 'Input contains a non-alphabetical character.'
>>
>>53545739
>word starts with a consonant
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
fart
NameError: name 'fart' is not defined


>word starts with a vowel
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
ass
NameError: name 'ass' is not defined
>>
>>53544293
Some arsehole always has to put their name on something that isn't theirs.
>>
>>53545793
  File "python", line 6
vowel = ["a", "e", "i", "o", "u"]
^
IndentationError: unexpected indent
>>
>>53545728
>>>/adv/
>>
I just finished an intro to java course at a local community college and want to start working towards my first job in the field. Of course I'm still learning but need a goal.

What are some good entry level positions to get my foot in the door.
>>
>>53545875
But it's programming related
>>
>>53545895
not its not.

you want someone to take life decisions for you.
just because you said "code" doesn't make it programming related.

i'm closing your reply as off-topic.
>>
>>53545437
>>53545484
undefined behavior, you fucks
>>
>>53545926
Yes it does.

It wouldn't make sense to drop college to play games but programming has a benefit that might match that of a college degree in a related field.
>>
>>53545566
>dereference overhead
please leave, you don't belong here
>>
>>53545930
>undefined behavior
you have 10 seconds to explain why or i'm closing your reply as off-topic
>>
>>53545944
are you this retarded? have you ever written anything in your life except fizzbuzz?
>>
why can't i use standard library cin with cstdlib getline? if i use it even once in my program, getline instantly returns 0 (or EOF or something, i haven't actually explicitly tested its output) at eveyr call. i've tried flushing the stdin after every cin but ended up just having to rewrite everything in my program to use cin.getline instead because i'm working with C-strings.
>>
>>53545953
You still haven't explained why my post is undefined behavior, autismo.
>>
>>53545969
overflow, you worthless spoon fed shit stain!
>>
>>53545885
going to need more to get into the industry. Apply for some internships if you want, but I would mostly recommend information interviews to figure out what you need to learn. From there learn what people say is useful, show it off, and see where it takes you.
>>
>>53545977
don't use terminology you don't understand, spergo
>>
>>53545996
you don't understand the term? what the fuck are you even doing here?
>>
>>53545968
to answer my own question, evidently cin leaves a newline char in the buffer after you use it. i still don't understand why clear(stdin) and fflush(stdin) don't work
>>
>>53545969
>2016
>still unaware of overflow
/g/ everyone!
>>
>>53546039
if fflush(stdin) is the same as c, it's only defined for output not input so if you use it for input it may or may not work
>>
>>53546015
Overflow is not something that applies here, dumb shit.
>>
>>53546061
i think the implication is that you're not going to be using the function for any data type which is larger than sizeof(int). it wouldn't be very hard to alter it for more portability

why is everyone always so invested in the idea that the person they are talking to is an idiot?
>>
>>53546068
please tell me you have an actual mental illness
>>
>>53546099
>data type which is larger than sizeof(int)
Do you even know what overflow is? It has nothing to do with sizeof(int), dip!
>>
>>53546109
there are some different applications of the concept "overflow" in computing. you're probably going to have to be more specific
>>
>>53546123
>be more specific
Look at the code, you shit!
>>
>>53546147
the only overflow issue i can see is when you try to cast a larger datatype to int and to operations on it, but if there's something we're all missing, by all means please elaborate. but unless you want to stop shitposting and say something substantial, this'll probably be the last bit of attention i'm going to give you.
>>
>>53546123
>>53546174
Do you see how the "concept" of function in the shown code uses the "concept" of subtracting 2 signed integers? The "concept" of overflow in the result triggers the "concept" of undefined behavior.
Fucking webshits!
>>
it's android studio the proper way to code for android?
>>
>>53546188
did daddy not love you enough?
>>
>>53546214
is this the new damage control style?
>>
pigLatin :: String -> String
pigLatin string = unwords (map latinWord (words string))
where
latinWord (x:xs) = xs ++ (toLower x : "ay")
latinWord x = x

Haskell is a fun language!
>>
Attempting the Synacor challenge
I pass the initial tests provided, but for some reason the provided program goes into an infinite loop, even everything *should* be working fine
>>
>>53546223
damage control would imply that there was damage done in the first place. i'm not the one personally invested in talking shit to online strangers anonymously on the internet for an ego boost :^)
>>
File: tumblr893749387434.png (129 KB, 2400x2239) Image search: [Google]
tumblr893749387434.png
129 KB, 2400x2239
>>53546123
You've clearly never tried to average 2 ints!
>>
>>53546276
int solve_the_meme(int a, int b) {
if ((a < 0) == (b < 0)) {
return a/2 + b/2 + (a%2 + b%2)/2;
}
return (a+b)/2;
}
>>
>>53546254
>I'm simply too stupid to observe the mistake in 1 line of code after I was made aware of it in half a thread
>>
>>53546295
>proving my point
>>
>>53546254
>talking shit
New code words for "I got told"?
>>
>>53546310
>maximum embarrassment
programming is just not for you, lad
>>
please make the shitposting stop
>>
Yeah, morons that can't even subtract 2 numbers should just go back to their homescreen thread!
>>
>>53546341
KEK
>>
>>53546099
>why is everyone always so invested in the idea that the person they are talking to is an idiot?
>goes ahead and proves he's an idiot
They never learn! :^)
>>
>>53546323
i can admit i'm not as strong a programmer as a lot of people in this thread. i have no issue with that. if my understanding of what's going on was incomplete, okay.
>>53546315
i don't feel particularly "told." i feel like i've been dealing with someone who's pretty unhappy about something. again, if i'm wrong, please feel free to point me towards where i can learn from it.

but let's be real, nobody really gives a shit about anything but propping up their own egos in their "safe space"
>>
>>53546361
>definition of backpedaling: the post
>>
>>53544293
roll for c
>>
>>53541936
Is anyone else here 10x status?
>>
>>53546405
me why?
>>
>>53546410
just checking
>>
>>53546400
perfect
>>
>>53546395
how am i backpedaling?
>>
>>53546421
with your foot
>>
>>53546444
i'm not using my feet, anon. i'm using my hands. my fingers, more precisely. don't you need two feet to backpedal? i don't own a bicycle.
>>
>>53546453
no him but i'm 20 and i dont know how to ride a bike
>>
>>53546405
here
http://pastebin.com/LuFAD96C
>>
android studio or eclipse.
which one and why.
>>
>>53546499
Eclipse
>why
because I dont give a shit what you do
>>
>>53546467
how are you ever going to make it as a webdev if you can't ride a bike or grow a beard?
>>
public class Lel { 

public static final Lel topLel = new Lel();
public static final Lel lel = topLel.topLel;
public static final Lel bottomLel = topLel.lel;

}
>>
>>53544868
Thanks for the help.
>>
>>53546208
It's as close to a "proper" way as we're going to get.
Use C/C++ libraries where you can, they'll run just as fast as they would on any linux OS, but obviously are limited to backend shit.
>>
I fucking hate make, is there a better way to do this?
vm: main.o chipset.o mmu.o processor.o disk_hub.o pic.o pit.o *.h ../common/*.h ../common/common.o ../common/mm.o
$(CC) ../common/*.o *.o $(CFLAGS) $(LDFLAGS)

main.o: main.c *.h ../common/*.h
$(CC) main.c $(CFLAGS) -c

chipset.o: chipset.c *.h ../common/*.h
$(CC) chipset.c $(CFLAGS) -c

mmu.o: mmu.c *.h ../common/*.h
$(CC) mmu.c $(CFLAGS) -c -O1

processor.o: processor.c *.h ../common/*.h
$(CC) processor.c $(CFLAGS) -c -Os

disk_hub.o: disk_hub.c *.h ../common/*.h
$(CC) disk_hub.c $(CFLAGS) -c

pic.o: pic.c *.h ../common/*.h
$(CC) pic.c $(CFLAGS) -c

pit.o: pit.c *.h ../common/*.h
$(CC) pit.c $(CFLAGS) -c


Basically instead of manually typing out the build command for every file, which is fucking stupid, I just want to loop over them instead.
Will Cmake solve this?
>>
File: 1445270823145.jpg (88 KB, 640x640) Image search: [Google]
1445270823145.jpg
88 KB, 640x640
>tfw when it finally works
>tfw when it was all worth it
BASED feeling, desu.
>>
>>53544293
rolling
>>
>>53544293
beam me up
>>
>>53547251
re-beam me with something i haven't already done
>>
If I wanted to overload a << operator to print a set, how would I do so? Each set contains a room, where a room is defined to be a contain a short int roomNumber(n), short int capacity(c), and short occupants(oc). Occupants is a list of names. While we're at it, how do I implement this set? Studying for a test on c++, could use some pointers. http://csiflabs.cs.ucdavis.edu/~ssdavis/40/Final%20Handout%202.pdf
If someone wants more information on the problem, here it is.
>>
>>53546947
Make already knows how to compile a .o from a .c, you don't need to specify any of that. Just replace the entire makefile with:

vm: main.o chipset.o mmu.o processor.o disk_hub.o pic.o pit.o


You don't need .h files on the vm rule, linking only depends on object files. And the .h stuff shouldn't be manually done:

https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html

It will use gcc to generate rules for your headers and include them. Or just use GNU autotools.
>>
>>53547453
But what about parallel building?
>>
File: s.png (151 KB, 421x500) Image search: [Google]
s.png
151 KB, 421x500
>>53546947
>Cmake
>>
>>53547474
make -j
>>
ideal starting python textbook?
>>
>>53547474
Use -j with (num_of_cores * 2) + 1, i.e. if you have a quadcore CPU:

make -j9

It's generally not a good idea to hardcode build threads into makefiles, but there's nothing stopping you making an alias like

alias mj="make -j9"
>>
>error: 'for' loop initial declarations are only allowed in C99 mode

so this fucking happened... added the -std=c99 flag but still nothing
>>
>>53547510
why the fuck isn't this the default behavior?
every fucking day, I find out something completely new and gamechanging about gnu make, it's both exciting and infuriating
>>
>>53547513
Put your incrementers outside of the for loop
also don't mix code and variable declarations
>>
>>53543205
start with getting a new chair
>>
>>53547560
I tried to find a source on the 2N+1 jobs thing, turns out it's basically a meme.
Something to do with a job for each thread, plus one for every hyperthread (x2), and then one ready to go as soon as the next job finished.

If you just want to compile as fast as possible, even if that makes your system near unresponsive, just use make -j and it'll work out the jobs for you.
>>
>>53544079
I am not >>53544052, but i recomend seeing https://www.youtube.com/watch?v=Rub-JsjMhWY
i just watched a video today of his about java. it is kind of fast. you are gonna need to pause a lot. good luck and have fun. welcome to the wide world of c++
>>
I'm new to programing. I've got an app idea, and I'm willing to learn. If I work about ten hours a week how long do you think it would take me. I want a special audio player for a type of podcast. Charge a few cents per article.
>>
Where's the hime at?
>>
File: Screenshot_2016-03-17_23-47-19.png (25 KB, 1600x899) Image search: [Google]
Screenshot_2016-03-17_23-47-19.png
25 KB, 1600x899
Making Pascal's triangles
Not posting the code cuz it's messy as fuck
>>
>>53544293
roll
>>
I have a dynamically allocated object.
This object has a private pointer.
Setting this pointer to null within the constructor of the object is giving me an "Invalid write of size 4" in valgrind.

Anything stand out to you guys?
>>
>>53548164
C++ compiled in g++
>>
>>53547892
Would anyone object to me photoshopping hime's face over those stuffy and boring pictures of stroustrup?

>>53548164
do you mean private pointer as in a pointer to an incomplete data type?
>>
https://www.youtube.com/watch?v=ZslV3s6wu5c
https://www.youtube.com/watch?v=xXyZ4YaktyU

Some really good talks here.
>>
>>53548164
Post your code.
>>
>>53548175
It's a pointer to some other defined class.
Thread replies: 255
Thread images: 33

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.