[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

/dpt/ - daily programming thread


Thread replies: 355
Thread images: 27

File: 1422360335034.png (49KB, 1000x716px) Image search: [Google] [Yandex] [Bing]
1422360335034.png
49KB, 1000x716px
The "RIP object oriented memes (1969-1990), it was not a pleasure knowing you, but you made me truly love Haskell, which is nice." Edition

Old: >>54665664
>>
File: jew slayer.png (2MB, 1920x1080px) Image search: [Google] [Yandex] [Bing]
jew slayer.png
2MB, 1920x1080px
First for fuck the kikes
>>
>>54671233
kill yourself
>>
>>54671233
Oh, a /dpt/ about languages nobody use. Nice.
>>
>>54671247
Why do liberuls only talk about the man-woman pay gap but never about the jew-goyim pay gap?
>>
Stop making threads before we hit the bump limit you fucking attention whore.
>>
File: haskelel2.jpg (745KB, 1920x1080px) Image search: [Google] [Yandex] [Bing]
haskelel2.jpg
745KB, 1920x1080px
>>
>>54671282
Stop giving attention whores attention you stupid goyim
>>
>>54671280
quit false flagging, idiot

ironic shitposting is still shitposting
>>
>>54671221
Thanks for help, I wasn't aware of this, fixed it right away.
>>
>>54671233
Haskellfags act all enlightened and above it all but rarely do they know lambda calculus. They're basically hipsters who got beyond Javascript.
>>
>>54671340
What CS degree doesn't cover the lambda calculus?
>>
>>54671347

You're assuming that most of the haskell pushers actually have CS degrees.
>>
>>54671347
Pajeet's degree didn't
>>
>>54671276
kek fucking jehovah's witnesses get paid 24k to go door to door?
>>
I still can't figure out where I'm going wrong.

My driver:
#include <iostream>
#include "ArrayList.h"
using namespace std;

int main()
{
ArrayList<int> a;
}


My header:
#ifndef ARRAYLIST_H
#define ARRAYLIST_H

template<class ItemType>
class ArrayList
{
public:
ArrayList();

bool isEmpty() const; // Checks if list is empty.
int getLength() const; // Returns the amount of times in the list.
bool insert(int index, const ItemType& item); // Inserts an item at index.
bool remove(int index); // Removes item at index.
void clear(); // Deletes every item in the list.
void whatIsAtIndex(int index); // Figure out how to throw an exception here.
int findItem(const ItemType& item); // Finds an item, then returns the index it was found.

private:
// Data members
static const int CAPACITY = 100;
ItemType list[CAPACITY]; // Array of items.
int itemCount; // Current amount of items in list.
};
#endif


cpp for just the constructor:
#include "ArrayList.h"
#include <iostream>
using namespace std;

template<class ItemType>
ArrayList<ItemType>::ArrayList()
{
itemCount = 0;
}


And then my error:
g++ driver.cpp
/tmp/ccsx8Q5G.o: In function `main':
driver.cpp:(.text+0x16): undefined reference to `ArrayList<int>::ArrayList()'
collect2: error: ld returned 1 exit status
>>
>>54671384
It's more that the people vulnerable to Jehovah's witnesses tend to be poor. Just like how Jews are at the top because a certain Austrian fellow got rid of the poor ones.
>>
>>54671384
they do it for free
>>
File: 1396234462139.gif (973KB, 190x149px) Image search: [Google] [Yandex] [Bing]
1396234462139.gif
973KB, 190x149px
Reposting for new thread:

I wrote a blog post about some template metaprogramming shit I did in C++.

http://anthony.noided.media/blog/programming/c++/ruby/2016/05/12/mruby-cpp-and-template-magic.html

Is it understandable? They say that the best way to learn something is to explain it. I think I definitely learned something, but I'm not sure my explanation is quite up to snuff.
>>
File: error.png (37KB, 713x524px) Image search: [Google] [Yandex] [Bing]
error.png
37KB, 713x524px
So, I couldn't debug my shitty calculator in my new phone.

So, I remade a test new project with the default values the wizard produce, and it gives me this error.

default libgdx project made by wizard.

So don't blame me for it.
>>
>>54671409
Definitons for templates must be in the same file.
>>
>>54671410
jews also have nepotism and are unscrupulous in terms of morals
>>
>>54671410
*bzzzzzzzzt*
>>
>>54671384
Welfare

>>54671376
http://www.strawpoll.me/10272941
>>
>>54671410
They got rid of the Jews because those damn Jews somehow controlled the whole economy
>>
>>54671439
>http://www.strawpoll.me/10272941
you're delusional, you're not smart or superior in any way just because of the programming language you use, it's not like haskell is hard to learn, in fact you're probably stupid as shit for falling for the meme and using such a shitty shit language, even FP nerds agree that haskell is shit
>>
>>54671459
Why are you so triggered Pajeet?
>>
File: 1459865687594.jpg (65KB, 458x328px) Image search: [Google] [Yandex] [Bing]
1459865687594.jpg
65KB, 458x328px
>>54671276
Good question
>>
>>54671491
why are you so delusional fag?
>>
>>54671456
Fucking /pol/ go >>>/pol/. The establishment will always blame outsiders. The US has done it with Russia and now "terrorists," the conclusive scapegoat that only exists in a limited sense for a postmodern era.

PROGRAMMING.
>>
fuck shillary

vote trump
>>
Is java or javascript better for beginners.

Last time I went to code academy I had a great time with javascript but couldn't finish it because my tablet broke.

Java feels odd for some reason. Or should I learn python first.
>>
File: 1463796563322.png (43KB, 894x744px) Image search: [Google] [Yandex] [Bing]
1463796563322.png
43KB, 894x744px
Hello stallman, my old friend. You look glorious in my terminal
>>
>>54671603
java

javascript and python are easier to get started with but they're shit for actual programming

java helps you learn more serious programming
>>
File: mqdefault.jpg (17KB, 320x180px) Image search: [Google] [Yandex] [Bing]
mqdefault.jpg
17KB, 320x180px
>>54671537
I'm not saying Jews deserve to be hated, in fact, they are probably superior to goyims. They are just better at not being worthless pieces of shit, but people have been jelly about this for a long time.
>>
>>54671618
He looks like he got in a bad fight.

>>54671603
Don't use javascript and don't use code academy.

Java is a better choice. I guess it depends on what you want to do, but I'd recommend C though.
>>
>>54671603
Start with Java, then learn haskell, Racket, and Javascript or Ruby
>>
>>54671627
kill yourself
>>
>>54671635
He got in a fight with 256 colors and resolution restrictions
>>
>>54671638
>>54671635
>>54671620
Thanks guys. I guess I will grit my tooth and learn Java.
>>54671635
Is there a better site for an idiot like me?
>>
>>54671664
Don't waste your time with C, only learn it if you need it for something
>>
What the fuck is wrong with this code? From experimental observations it seems it's not.
#define update_descr_addr(descr_list, addr_field, new_addr) do {            \
alt_sgdma_descriptor *cur = descr_list; \
size_t offset = 0; \
while (cur->control & ALTERA_AVALON_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK) { \
cur->addr_field = (void *) new_addr + offset; \
offset += cur->bytes_to_transfer; \
cur = (alt_sgdma_descriptor *) cur->next; \
} \
} while (0)
>>
>>54671664
https://docs.oracle.com/javase/tutorial/
>>
>>54671618
Hello Stallman my old friend
I've come to interject again.
Because a program softly creeping
Left its source while I was sleeping
And the vision that was planted in my brain
Still remains
Within the sound of freedom
>>
>>54671681
Except C is useful everywhere.
>>
>>54671686
s/not/not idempotent/
>>
>>54671603
Don't learn Java.

Python is better, or C, but I recommend Python.
>>
>>54671707
Everywhere that he needs it, which is hopefully nowhere. It is a terrible, weakly typed language. He should learn a modern systems language like Rust
>>
>>54671719
kill yourself

>>54671707
no it's not, for >99% of applications there are better-suited languages
>>
>>54671686
Why the fuck is that a macro? Are you literally retarded? You don't even have parens around the variable usage
>>
>>54671717
What? What the hell does idempotency have to do with anything? That's a functional property.
>>
Should I be writing macros for small inline-able functions instead of making proper functions?
>>
>>
>>54671681
Everybody should understand how C abstracts system memory from low level, and at least be able to read and understand C.

Then they should never actually use it for anything in <current year> because we have type and memory safe modern languages that have replaced it
>>
>>54671754
Because addr_field. Thanks for parens though.

>>54671764
You're moron.
>>
File: soccer slap.jpg (103KB, 460x648px) Image search: [Google] [Yandex] [Bing]
soccer slap.jpg
103KB, 460x648px
>>54671340
What does lambda calculus have to do with any specific language? It's an abstraction and it's used everywhere in compilers, interpreters, linters, etc.
>>
>>54671801
Idempotence is a function property and that macro isn't a function. If one were to wrap it into a C function it would have the void type, so it really couldn't be a function.

At the very least you could write in English instead of s/not/not idempotent.

t. Rule 3
>>
Hey /dpt/. I have no idea what to make but I really, really want to make something. Something that can be used, something mildly cool or entertaining, just something.

Any help?
>>
>>54671599
If you go for the microcontrollers, you'd want to learn C. I find it relativily easy to learn since it doesn't have a whole lot of abstraction.

For PLC there is ladder, function block diagrams and sfc. (And STL and SCL.) You have to remember that PLC's were developed for industrial work and the programming reflects that. sfc is fairly easy to learn as a beginner, but ladder and function block aren't al that hard either.
>>
Can someone give me 1 example or reason of why OOP is actually bad? Because I've never seen an actual example. And I'm not talking about ">muh Pajeets inherit everything" meme, I mean an actual reason why the tools are bad and not the people using them.
>>
>>54671917
it's 'latter'
>>
>>54671876
You're still moron, fucking hipster piece of shit.

I mean idempotence as in:
I'll put your neck on the ground and then I'll cut your fucking head off with a sword. And no matter how many times I'll punch the position where your neck was with the sword, your fat body and worthless head will be separated in the same state as they were after the first cut.

Only faggots try to correct usage that perfectly conveys the point.
>>
>>54671936
OOP itself is not bad. It is just misused and abused very often.
>>
>>54671987
It isn't in the Netherlands.
>>
>>54672006
look it up fambly
>>
>>54671936
it drives people to overengineer their programs which leads to them being unmaintainable. OOP is a great concept when used correctly.
>>
>>54671801
>Because addr_field

Just make it a void* parameter and use a function
>>
>>54671916
Make a rope and hang yourself. Only Pajeets lack creativity
>>
>>54671990
>conveys the point
>s/not/not idempotent
That conveys something? That looks like nonsense to me.
>>
>>54672083
I'm not pajeet, and I have ideas but they are all useless
>>
>> inb4 arduino c isnt a programming language.
I dont care.

Im working on an arduino project, and I need to know if you can call a function from inside another function.

for example:

void loop() {
// stuff happens
functionOne();
// other stuff happens
functionTwo();
// even more stuff happens.
}

void functionOne() {
// insert stuff that happens here
functionTwo();
// more stuff happens
}

void functionTwo() {
// even more stuff happens
}
>>
>>54671429
I tried looking that up: https://isocpp.org/wiki/faq/templates#templates-defn-vs-decl

And I'm still failing to see what I did wrong.
>>
>>54671750
>impying that embedded applications encompass <1% of all applications
>>
>>54672196
Of course you can. How could you call any function other than main if you couldn't call it in main?
>>
Dubs chooses what trivial program I write
>>
I'm going to install lubuntu to make games and there's nothing you can do to stop it.

;)
>>
>>54672196
Are you seriously learning arduino C as your first language? Of course you can you fucking retard.

>>54672225
Because Arduino doesn't use a main, it uses a setup() and a loop() or some shit (which main() calls, but it hides that from you)
>>
I'm working in Javascript and making what is basically a pick-a-path adventure type thing, and I've got each section defined as an object, and the sections the player can head into from that section as an array of variables on the object.

Except now I'm running into the problem where if a section's choice isn't defined above it's just undefined, and given some of them refer back in a circular manner I can't just make sure things are defined in order.

In a simplified example, I'm basically having this issue:
var bob = 
{
name: "Bob",
buddy: alice
}
var alice =
{
name:"Alice",
buddy: bob
}

function test()
{
alert(alice.buddy.name); //gives "Bob"
alert(bob.buddy.name); //gives "Unable to get property 'name' of undefined or null reference" error
}


I can probably replace the actual names with strings and then get them using those, but there isn't another more sensible way to be laying these out, is there?
>>
>>54671999
>>54672037
So OOP itself being bad is just another /g/ meme then? Thanks.
>>
>>54672196
>arduino c
no such thing exists
>>
>>54672237
Well the same argument applies to setup and loop.
>>
>>54672229
have fun
>>
>>54672198
It's best to define and *declare* template classes/functions in the same file, and later include it wherever you need it.
>>
>>54672239
I don't know fucking shit about javascript but is it because bob's buddy is defined as alice before alice exists
>>
>>54672229
What sort of things are you going to make?
>>
>>54672229
I hope you prayed to the video driver gods.
>>
>>54672239
var bob = 
{
name: "Bob"
}
var alice =
{
name:"Alice"
}

bob.buddy = alice;
alice.buddy = bob;


Pretty trival stuff
>>
>>54672229
sent
;)
>>
>>54672225
>>54672237

What that guy said.


>>54672237

And yes, I did learn arduino C as my first language. Since then I have learned "jython" which is supposedly fully compatiable with python, but it isnt. My university's intro CS class is stupid. They should have just taught us python. Jython is great for learning how programming works, but not for actually programming stuff outside of the course...

Its supposed to be python implamented in java, but it isnt exactly.
>>
>>54672279
android shit, libgdx, opengl in python and c++
goo shit
SDL/SFML/Monogame

All the good package.

need now to find an open source alternative to melodyne editor
>>
Best resources for learning C?
>>
>>54672244
its supposedly just regular C but with arduino headers on it. Its not the same thing as learning C though. Cant be used to program an actual computer.
>>
>>54672275
In his defense that's legitimate in lots of situations. It's legitimate in Java.
public Main {
public static void main(String[] args) {
foo();
}
private int foo() {}
}

Scheme:
(define (foo) (bar))
(define (bar) #f)
(foo)


>>54672299
I don't know shit about java but wouldn't it be more idiomatic to do this?
var bob, alice;
bob =
{
name: "Bob",
buddy: alice
}
alice =
{
name:"Alice",
buddy: bob
}

This is similar in form to how letrec is implemented in Scheme.
>>
>>54672348
GCC, a text editor and a reference manual to the C standard library and C syntax.
>>
>>54672351
it's c++
>>
>>54672357
>wouldn't it be more idiomatic to do this?
Yes, that would work too, since it's reference
>>
>>54672348
C Primer Plus
C Programming: A Modern Approach
>>
>>54672299
That's fine for Bob and Alice, but in the 3-event demo I'm working on now I've got 24 different sections, and the proper thing'll be significantly larger, so I want to keep each section's data together as neatly as possible.

>>54672357
>I don't know shit about java but wouldn't it be more idiomatic to do this?

I thought of that one myself, since it'd keep things neat and I thought *should* solve the issue of things being undefined, but nope, it was (and is, tested again to confirm I didnt' just screw up last time) giving me the same error as before.
>>
>>54672239
Just make Alice and Bob elements of an even larger object, and use strings
>>
You could do lazy initialization as in getBuddy: func() { bla bla }
>>
Which IDE do you guys use for general coding, VBS or JetBrains?
>>
>>54672410
>I thought of that one myself, since it'd keep things neat and I thought *should* solve the issue
That's because var a; is still undefined, you have to do var bob = {}; var alice = {} first
>>
>>54672258
Thanks.
>>
Here's what it's like to be a developer in China
https://news.ycombinator.com/item?id=11744736

>9am until 11pm
>6 days a week
>Still make less than the lowest paid developer in the US
>>
File: 68000.jpg (404KB, 1024x768px) Image search: [Google] [Yandex] [Bing]
68000.jpg
404KB, 1024x768px
So I was at the computer labs at school, and saw in the recently used programs, someone was using some IDE/Compiler/thing for the Motorola 68000. I looked up what the Motorola 68000 is, and it seems archaic.
Would someone be using it to learn assembly? Maybe an intro to embedded systems class or something? Also why do people still use assembly?
>>
>>54672463
I use emacs for C, Lisp, Ruby, and Go. I also use it for code review, and for pair programming across the world where me and some guy in Norway share an emacs buffer

I used eclipse for java when I did some elastic search work and hated it so much I just switch to emacs and scripted my own tests
>>
>>54672522
You wouldn't use a random architecture to learn assembly; you'd learn assembly for the architecture you want to make stuff for.
Either he was just curious and interested and fucking around, or wants to fuck around with an old machine he has
>>
>>54672522
They use machine-level code for performance evaluation and optimization, and to reverse engineer or debug compiled code.

There's a reason the Art of Programming is done in an assembly language which is to learn how optimization works on the machine level.
>>
>>54672522
Assembly is useful to know because it gives you a better sense of what's going on your computer and what exactly your code is turning into.

>>54672463
Vim + Command prompt in a terminal mutexer.
>>
>>54672522
microprocessors class
>>
I had a software dev. job interview recently. The interviewer said that the position wasn't just a "software developer" but "a product developer" and a "product focused company". What did he mean by that? What extra responsibilities should I expect? The job ad most definitely was "software developer". The company is a bank.
>>
>>54672471
Ah. Yeah, that'd work if I replaced the second
bob={stuff};
with
bob.name="Bob";
bob.buddy=alice;
Thanks for explaining where I was goofing there.
>>
>>54672575
>Vim + terminal mutexer
>Emacs
Only two valid answers.
>>
>>54672463
Vim and CLI utils. I have a tiling wm so I don't use a multiplexer
>>
>>54672848
same but I still like using tmux over tiling wm
>>
//Help with Java?

class Node {

int value;

Node left;
Node right;

Public Node {
}
}

// Allegedly this is the structure for a node in a binary tree. When you type 'Node left/right', I know that it represents the sons of this node, But why does it work? How can you write the name of a class inside the same class?
>>
>>54672894
Why?
>>
>>54672913
I really like tmux/screen's windows, tiling WMs can't really provide anything like that (at least in my experience) with static workspaces. Also, tmux integrates really well with vim splits so I can use things like ctrl H/J/K/L to move around vim splits and tmux panes seamlessly
>>
>>54672903

To elaborate. How does 'Node left' helps me to know the address of the left node? It's not even a variable or anything. Is this class going to create a Node object with two node objects inside, and then each one of those will have two inside and so on? If that's the case, Wouldn't having an infinite structure eat all my memory? When does it stop?
>>
>>54672903
long story short , its a recursive implementation

http://www.newthinktank.com/2013/03/binary-tree-in-java/
>>
I think I want to start an offshoot of Thule that supports lookbehind conditionals. Then you could customize certain outcomes on the basis of previous replacements rather than duplicating a ton of text with the only difference being a single replacement rule.
Man, can you believe these *(political_party)? All they care about is *(P ?? "liberal" -> "liberal_issues" : "conservative_issues").


Something like that, where P means previous.
>>
>>54672938
i3 doesn't use static work spaces. I use the vim keys to move around the windows. It's exactly like tmux as far as I can tell except I can do more than just terminal windows
>>
>>54672903
in Java, anything that has a class is a pointer.

think
typedef struct {
int value;
Node* left;
Node* right;
} Node;
>>
>>54672938
Why not use a real tiling WM like Awesome?
>>
File: 1433723486751.png (1001KB, 1312x2187px) Image search: [Google] [Yandex] [Bing]
1433723486751.png
1001KB, 1312x2187px
Any language that doesn't give you explicit control over the lifetime of an object is complete and utter garbage.
>>
>>54672957
it's a variable, it's a reference to a Node object. it doesn't go on forever, they default to null (no object)
>>
>>54673080
if you keep on allocating and deallocating objects it can be inefficient, it can be more efficient to use a pre-allocated heap and amortize the cost of removing objects so you do it all at once instead of a little a time
>>
>>54673080
You are utter garbage
>>
>>54673184
not to mention memory fragmentation
>>
>>54673184
A better solution would be to allocate on the stack in that case.
>>
>>54673223
not if you have many objects and long lifetimes of objects
>>
>>54671603
lisp
>>
>>54673234
>long lifetimes of objects
Then allocating on the heap shouldn't be a problem.
>>
>>54671603
>>54673247
Common Lisp or Racket.
>>
>>54673250
you can get memory fragmentation and you're constantly taking time to allocate and free objects piecemeal, it can be much better especially for long-running applications like servers and enterprise applications to have a garbage collector to not do anything until it's necessary, then it does everything all in one go and it can move things around to defragment memory
>>
GC langs are among the fastest for long-running applications

https://www.techempower.com/benchmarks/#section=data-r12&hw=peak&test=query
>>
>>54673080

Everything should have static lifetime.
>>
>>54673381
Kill yourself.
>>
with separate malloc calls you don't get explicit control over the memory layout anyway, you're at the mercy of the operating system
>>
>>54673411
ctards on suicide watch amirite?
>>
>>54673277
>Common Lisp
>>
>>54673411
That's got nothing to do with the lifetime of an object.
And who said we were talking about C here? C++ also gives you explicit control over object lifetimes.
>>
Does C have any standard hashtable libraries?
>>
>>54673428
you can really shoot yourself in the foot if you're not super good at managing memory, like if you alloc a """"2d array"""" on the heap with separate malloc calls, it's pig disgusting, now imagine the same kind of thing but on a much larger scale across your entire program
>>
>>54673408

No, for I also have static lifetime. I have been here from the beginning and I will be here until the end.
>>
>>54673456
Yeah sure, I agree that's a shitty way to allocate a 2d array, but only a retard programmer would do that.
I know better than that though.

What the hell is your point? memory management can be dangerous? no fucking shit. Learn to program properly, problem solved.
>>
>>54673490
GC has its uses and is much better than Ctards give it credit for, you don't get optimal performance automatically just because you do manual memory management
>>
>>54673435
The standard C library doesn't include any large, persistent data structures - neither lists, nor trees, nor stacks, nor hashtables.

It's not really possible to give a definitive answer without asking the authors of the original C library. However, a plausible explanation is that the implementation of such data structures involves various tradeoffs, and only the author of the application is in the correct position to make those tradeoffs.

Note that the POSIX standard C library does specify generic hashtable functions: hcreate(), hsearch() and hdestroy(); and note also that their "one size fits all" nature tends to render them inadequate for most real-world use cases, supporting the argument above.
>>
>>54673519
But with GC you lose explicit control over object lifetimes.
That is not a worthwhile trade off for me.

And while you argue that is GC useful for efficiently deallocating objects and lowering memory fragmentation, don't forget that the GC pass itself has overhead that in some languages can be pretty bad.
>>
>>54673435
https://apr.apache.org/
>>
>>54673456
Big malloc()s (>128 kB) usually don't end up on the heap but as anonymous mappings
>>
File: Untitled.png (35KB, 988x570px) Image search: [Google] [Yandex] [Bing]
Untitled.png
35KB, 988x570px
Why does this shit crash when I run it 'fast'?
Meaning that if I manually debug through this code it works, but when I simply run it, it goes beyond the range limits.

 
// compute fitness of each individual in the population
var fitnesses = Enumerable.Range(0, populationSize).Select(i => computeFitness(currentPopulation[i])).ToArray();


public static double ComputeFitness(Individual individual)
{
return individual.binaryString.Count(character => character == '1');
}


Somehow it's sending a 6th Individual that is null.
I seriously cannot comprehend why this shit is happening.
>>
How do you floor a float to an int in C /dpt/?

This is what I got but maybe there exists better ways:
int floored = lrint(floor(x));
>>
>>54672640
It means the bank is using buzzwords to try to sound relevant.
>>
>>54672640
i'm guessing it's not just a code monkey job, you're taking part in designing the software product, not just programming things according to a predetermined specification
>>
>>54672239
>>54672299
>>54672357

Why is it always Bob and Alice Goddammit, definitely NOT OTP
>>
File: bitch-hold-on.jpg (55KB, 480x720px) Image search: [Google] [Yandex] [Bing]
bitch-hold-on.jpg
55KB, 480x720px
>>54672327
>jython
>python written in java

what is this super meme and where did it come from?
>>
>>54673977
It's actually good. It doesn't have the GIL
>>
>>54673977
Literally all the gay languages(python, ruby...) have compiler that can compile to .net clr, jvm and probably c.
>>
without resorting to memes, someone please explain why javascript is bad. i think its because you guys just dont understand how to use JS debugging tools properly and think prototypal inheritance is scary (muh oop!!!)

:^)
>>
>>54674071
insert the truth table here
>>
>>54674071
==
>without memes
You aren't the boss of me.
>>
>>54671603

after you get the basics of codecademy out of your way i suggest picking a small toy project like maybe a webscraper or a todo app and then trying to write one - if you get stuck consult the documentation for whatever language you chose or google
>>
>>54674071
Yeah, is Java really that bad?

I planned on using Java to make a social media app in my spare time. I assumed it was time to hop on the hype, but i'm not experienced with servers, and web app development at all, and I don't wanna waste my time.

What do?
>>
>>54674126
>>javascript
>Java
>>
File: anime2016.jpg (12KB, 200x200px) Image search: [Google] [Yandex] [Bing]
anime2016.jpg
12KB, 200x200px
So I would like to create navigation using a select element on my page. Using the RouterLink directive on an anchor tag is simple, but is there an equivalent for a select dropdown? Or am I required to create my own navigation method on my component to be called when there is a change on my select?

<a [routerLink]="[location]">Location</a>

<select (change)="navigate($event.target.value)">
<option>--Select Option--</option>
<option [value]="[location]">Location</option>
</select>


I am looking for something like this:

<select>
<option>--Select Option--</option>
<option [routerLink]="[location]">Location</option>
</select>
>>
>>54674136
Get with the times, grandpa
>>
File: 1457321273831.png (16KB, 303x880px) Image search: [Google] [Yandex] [Bing]
1457321273831.png
16KB, 303x880px
>>54674173
>angular
>>
>>54674175
what
i was pointing out that JS and Java are two entirely different things
>>
>>54674173
Just use PHP like a normal human.
>>
>>54674206
REEEEEEEE
>>54674253
EEEEEEEEE
>>
>>54674248
I meant javascript .

I'm just hip, posh, and lazy
>>
>>54674278
you can't do that
>>
>Groovy

Is there a worse meme language?
>>
>>54674305
sorry
>>
>>54672640
>https://news.ycombinator.com/item?id=11744736

the product guys at the last place i worked at did zero coding and spent most of their time talking to the devs, customers and management figuring out a clear path for what features to implement into our products

not something i'd want to do but it seems like it paid about the same as the devs were making
>>
>>54674278
>>54674126

>>>/g/wdg

python with django is the hip new thing for webshit, but if you're serious you should use java or C++
>>
>>54674356
Isn't Go the new 'hip' server programming language
>>
>>54671783
is this fake? my logic says it is fake but can't find a flaw
>>
tfw i spent the last week looking at assembly and reverse engineering parts of a 15k$ commercial software so now i can make save files for the said software in about 50 lines of python code
>>
>>54674392
maybe, these memes come and go pretty quick, like ruby on rails used to be big, then node.js, then python (django/flask), maybe python is on its way out, but i think go might be too hard for most web devs
>>
>>54674126
>i'm not experienced with servers, and web app development at all, and I don't wanna waste my time.

bruh youre gonna waste so much time

things you'll need to know

basic linux shit, basic webserver shit, html, css, templating, whatever lang and framework you want to use for you backend/API then JS and whatever stupid hipster framework you choose for that
>>
>>54672497
Damn, that is bad. Allthough I doubt it is any different than any other expertise in China. At least do they getting paid more than average?
>>
>>54674126
>java
>social media app

kill urself m8
>>
>>54674432
The problem is that you're asking web designers to write code. Just calling themselves web "devs" instead of designers doesn't make them magically better at programming.
They need some meme framework written in a meme language to make sure their horrible written code still works without blowing anything up.
>>
>>54674434
You think i could circumvent JS with C++, considering i know that much better.

and what would be a proper template?
>>
>>54674523
>considering i know that much better
Than just use that. There are frameworks for anything in any language.
>>
>>54674523
i mean go for it but if you think you can develop a modern website/webapp without any frontend code you're gonna be in for a bit of a shock

your app is most likely gonna render info from whatever data source you have (oh totally forgot you should probably understand databases and ORMs too) and then use a template to create HTML for the browser to read. first template/templating engine that comes to mind is Jinja2 but there are tons of them
>>
>>54674515
Web designers are web designers, backend developers are different cup of tea. And since nearly every system nowadays has a web interface most programmers becomes webdevs
>>
>>54674515
>>54674580

the designer and the person who implements the design in angular/react/whatever has almost always been a different person at every place i've worked
>>
>>54674580
>And since nearly every system nowadays has a web interface most programmers becomes webdevs
even i am gonna have to do some web backend shit ;_;

>>54674578
his app could render things natively, doesn't have to go through the browser
>>
>>54674619
true, but most pages these days have JS. not really a fan of JS bloat but that's how it be
>>
>>54674651
i think when he said 'doesn't have to go through the browser' he meant that it doesn't hace to go through the browser
like it doesn't have to be a webapp, but with good old native client
>>
>>54671537
>PROGRAMMING

You mean name-calling, product shilling and asking for help with school assignments? Because that's all /g/ is for.
>>
>>54674578

What if i try to circumvent even further, using a P-T-P method. Can smartphones even do large-scale Peer to peer properly?
>>
File: INNERLOOPOPTIMIZED.png (44KB, 741x612px) Image search: [Google] [Yandex] [Bing]
INNERLOOPOPTIMIZED.png
44KB, 741x612px
>>54674731
Also, people asking "which language to learn".

Few things bother me as much as that debate.
>>
>>54673456
>i like Rust because it protects my feefees from being hurt by mean patriarchal memory management issues
>>
>>54674830
don't do it
>>
File: 1459484904280.png (5KB, 414x15px) Image search: [Google] [Yandex] [Bing]
1459484904280.png
5KB, 414x15px
;_;
>>
When do you choose functional programming over object oriented?
When you anticipate a different kind of software evolution:

Object-oriented languages are good when you have a fixed set of operations on things, and as your code evolves, you primarily add new things. This can be accomplished by adding new classes which implement existing methods, and the existing classes are left alone.
Functional languages are good when you have a fixed set of things, and as your code evolves, you primarily add new operations on existing things. This can be accomplished by adding new functions which compute with existing data types, and the existing functions are left alone.
When evolution goes the wrong way, you have problems:

Adding a new operation to an object-oriented program may require editing many class definitions to add a new method.
Adding a new kind of thing to a functional program may require editing many function definitions to add a new case.
This problem has been well known for many years; in 1998, Phil Wadler dubbed it the "expression problem". Although some researchers think that the expression problem can be addressed with such language features as mixins, a widely accepted solution has yet to hit the mainstream.
>>
>>54674934
>When do you choose functional programming
never
>>
>>54672522
he's very likely using it to program a ti-89, heh
>>
What would be the benefit of coding a server in C over C#?
>>
>>54674981
code it in Rust instead
>>
>>54674919
why not?
>>
>>54674981
The benefit would be that you would learn a lot about how servers work.
>>
>>54674981
lower latency
lower memory usage
lower power consumption/CPU usage
>>
>>54674981
C is a programming language, not a coding language.
>>
Reminder that Haskell cannot have good performance or low memory usage because it uses lazy evaluation.
>>
>>54675040
coding and programming are synonyms
>>
>>54675059
no their not
>>
>>54675059
they're not tho
>>
>>54675059
They're not.
HTML is a coding language.
C is a programming language.
Learn the difference and fuck off.
>>
do people still use B to program? I may pick it up
>>
>>54674981
Just like any other C vs. C# dilemma: you have more control in C. Using a higher-level language like C# is great for doing first builds, prototypes, etc My guess is that anything that you make won't need to operate at scale just yet so you could get away with the heavier abstraction of C#. Ultimately it's your choice, but I do believe you will have to write quite a bit of boilerplate if you opt for C. Boilerplate isn't bad. Just do it well the first time so you have it for the future. :^)
>>
>>54675101
C++ is an option because you can much better control how much cost you introduce with abstractions than you can with C#.

Another option might be Rust, which has an emphasis on zero-cost abstractions.
>>
>>54674981
because making a server in a language without threads, networking, hell even a queue structure is ``fun''

We had a C++ server at job. Impossible to debug and very error prone, a great combination indeed.

>inb4 C fags call names

I use C++ at job for client side, but it sure is not a server language. C is even more guilty.
>>
I'm trying to calculate total memory usage using /proc/<pid>/statm and comparing my numbers to the system manager and getting some weird numbers.

I'm basically adding all the numbers I get from statm, is that wrong?
>>
>>54675154
>c
>lacking threads
>networking
>queues
kek

Besides you don't need threads or queues or really networking to program cgi pages.
>>
>>54675059
No.
>>
>>54675096
like 1 person MAYBE
>>
>>54675189
point me to the standard that says anything about networking
>>
>>54675227
>It's not in the standard so you can't use it.
>>
>>54675101
>My guess is that anything that you make won't need to operate at scale just yet so you could get away with the heavier abstraction of <shitlang>
that's what every web startup thinks until they end up with millions/billions in annual losses because of server hosting expenses
>>
>>54675244
Then you will need to depend on possibly platform dependent libraries, which is even more reason not to use C.
>>
>>54675277
>Oh no! I have to use a platform dependent library!
Most libraries are platform independant, unless you're targeting Windows, but who cares about Windows anyway.
>>
>>54675081
>HTML is a coding language.
no it's not, it's a markup language
it's even in the fucking name
>>
>>54675277
Brotip: everything is platform dependent.
Double brotip: servers are designed for particular hardware.
>>
>>54675302
This

Only gay men use Windongs
>>
>>54675309
Markup languages are coding languages.
>>
>>54675302
>Most libraries are platform independant, unless you're targeting Windows
holy fuck it does not get more retarded than that.

I am done C fags.
>>
>>54675251
Note that I said my guess, and my guess is that this is a solo guy just playing around. I pray that no actual entrepreneurial endeavour would come to /g/ for technical advice.
>>
>>54675342
Who the heck uses Windows except your parents and neckbeard gamers?
>>
>>54675328
wtf is a coding language ? there is natural language, programming language, and markup language.
>>
>>54675277
Porting a lightweight network library written in C is a lot easier than porting over the entire .NET framework and runtime.
>>
>>54675369
>muh arbitrary classification
No, there are recursive languages, context-free languages and regular languages
>>
>>54675376
this
>>
File: Untitled.png (236KB, 1366x768px) Image search: [Google] [Yandex] [Bing]
Untitled.png
236KB, 1366x768px
I'm looking for more websites I can use to gather data about an IP address, Where would I look?
https://en.wikipedia.org/wiki/Special:Contributions/68.173.233.165
^ anything at all, even if it's something stupid like that
pic related, what I'm using it for
>>
>>54675154
>Impossible to debug
that's because you're incompetent
>very error prone
because you're not a real programmer
>>
File: 1450278863418.jpg (86KB, 935x615px) Image search: [Google] [Yandex] [Bing]
1450278863418.jpg
86KB, 935x615px
Any smart C++ people here?
I have a base class "Body" that has a virtual function "OnCollision(Body* CollidingBody)", pretty self explanatory, happens when the body collides with another, but how do I figure out if CollidingBody is a certain derived class?

Doing
"if(CertainClass* certain = dynamic_cast<CertainClass*>(CollidingBody))"
Comes to mind, but shit's runtime so dynamic_cast might be slow. The only other option is to have an "BodyType" enum that covers all derived classes of Body so I can do
"if(CollidingBody->Type == CERTAIN_CLASS)"
This of course requires a bigass enum declaration and every derived classes constructor setting the Type appropriately.

I just don't know what the right approach here is.
>>
>>54675380
and yet there is still no such thing as a coding language.
>>
>>54675436
But in C there are no exceptions, so you can't catch segfaults and try again. It's a worthless language.
>>
>>54675458
But you're a retard and you're worthless.
>>
>>54675444
Put spaces after control keywords, i.e. favor if ( over if(.
>>
>>54675450
I can make an arbitrary classification that includes it

Any language that codes data is a coding language, bam, HTML is a coding language
>>
>>54675444
It is gonna be runtime no matter what.

Make a virtual function that returns type of object. Or keep 'type' on the most base class and set that on constructors
>>
>>54675470
>no exceptions
>no classes
C is WORTHLESS.
>>
>>54675444
>instanceof
>>
>>54675500
there is no instanceof in C++
>>
>>54675498
see >>54675470

>>54675458
>you can't catch segfaults and try again
holy shit
>>
>>54675399
>activate windows
>>
>>54673778
why not just
 var fitnesses = currentPopulation.Select(computeFitness);
>>
>>54675444
Why not just use dynamic_cast now and worry about optimization later when it becomes relevant? You need to test first, yes?
>>
>>54675498
>no exceptions
Just use goto
>no classes
See the Linux object model or GTK+'s GOM
>>
Stripping files off NOAA FTP site - why is this shit so damn slow? I wish I could connect more than once but they're pretty quick on the IP ban for that shit.
>>
>>54675444
Unfortunately C++ has shit tier dynamic dispatch support, so there's no convenient solution to this.
You have to hand code your own dispatching, using an enum is probably the easiest, could possibly create your own tool for generating them automatically for you.
>>
>>54675500
>instanceof
This isn't in C++. But the C++ equivalent is dynamic_cast.

>>54675489
Keeping a "BodyType Type" in the base class is what I'm probably going for right now. But dynamic_cast would just save so much code yet I know deep down it probably does some real hacky stuff in the background.

>>54675535
I guess this is a good idea. Gonna probably need bitfield maps for bodies anyways so I'm eventually gonna need to use the enum approach.
>>
>>54675521
>no argument

In Java you can catch these sorts of problems:

Foo getFoo(int x, long y) {
Foo f;
boolean succeeded = false;
while (!succeeded) {
try {
f = new Foo(x, y);
succeeded = true;
} catch (Throwable t) {
log.warn("Caught exception creating a new Foo. Trying again...");
}
}
return f;
}


You can apply this pattern to any operation that might fail. You can't in C.
>>
>>54675591
All it does is checking vtable and casting using that. But I would still go for BodyType type because you might need those enums for something else anyway. Imho, dynamic_cast to check type of objects looks weird
>>
>>54675611
f = new_Foo(x, y);
succeeded = true;

if (!f) puts("syntax is great");
>>
>>54675611
>You can't in C.
Of course you can.
struct foo *get_foo(int x, long y)
{
struct foo *f;
for (;;) {
int ret = foo_create(&f, x, y);
switch (ret) {
case FOO_SUCCESS:
goto done;
default:
log("error: %s\n", foo_errmsg(ret));
}
}
done:
return f;
}


although an infinite lop on retrying to create some object seems retarded.
>>
>>54675586
>could possibly create your own tool for generating them automatically for you.
Sounds like over-engineering, but interesting

>>54675622
Yeah, I guess I'm trying to embrace "The C++ Way" with dynamic_cast, but sometimes it just isn't worth it I guess.
>>
>used catch(...) in sepples
>doesn't catch vector out of bounds
Why is this meme language so popular?
>>
>>54675458
>how do i catch segfault without exceptions
Top Kek. Just don't segfault! The kernel is gonna kill you regardless of your language (assuming you don't do something incredibly hacky).
>>
>>54675666
nice trips

consider this though:
int return_some_integer(int x) {
int ret;
//... some calculation on ret
return ret;
}

Let's say the codomain for return_some_integer is all integers. (i.e. all integers are valid output). How do you know if the function succeeded?
>>
>>54675458
There are no segfaults in C either.
>>
Anyone here have experience in authoritative game servers?

I'm splitting up the servers into 3, say Login server > Character server > Map/World server

What would be the best practice for managing the databases? Should I give each server a separate database or have them all access the same database but just with their own separate tables they are allowed to access?

Also is this even the right way to go about it? Should I just have it all in one server instead or maybe two?
>>
>>54675710
stderr. Only user errors should throw exceptions btw.
>>
>>54675696
because there is no out of bounds exception. it would add overhead to every access operator on vector.

use a class that extends std::vector and override []
>>
>>54675710
>Let's say the codomain for return_some_integer is all integers. (i.e. all integers are valid output). How do you know if the function succeeded?
You add another output somehow.
Wrap the return value n a struct with value, errcode, add another output pointer argument or use a global/thread local error code system like errno.
>>
>>54675742
Vector already has .at precisely for that. That wasn't the point though.
>>
>>54675745
>Wrap the return value n a struct with value, errcode, add another output pointer argument or use a global/thread local error code system like errno.
or just use exceptions
>>
>>54675761
whoops didn't know that difference. I learned something today, thanks /dpt/
>>
>>54675710
Not him but I think of two ways:

One way
float foo(int x) {
if(x == 0)
goto K_FAILURE;
return 1.0f/x;
K_FAILURE:
push_error(FOO_BAD_ARGS);
}

Alternatively you could wrap the return output in a struct with an error flag, but above is how most libraries do it.
>>
>>54675745
I thought of the struct solution but boy is that ugly. I like the idea of a global error system though (used in libraries like SDL)
>>
>>54675782
Nah.
>>
>>54675710
>How do you
by not being a retard and designing a proper function
>>
>>54675458
>you can't catch segfaults
There's no need: there are no segfaults in C.
>>
>>54675816
What? The idea is that all integers are valid output but not all integers are valid input, meaning there can be user error.
Imagine performing this call:
 f = fopen("file", "abc"); 

Would you blame it on the author of fopen that this doesn't work?
>>
>>54675785
This is something which should have proper hardware support.
Would be cool to have a dedicated register/flag which holds error codes, then you could have really efficient error checking just be a single conditional jump on this flag.
x86 has the carry flag you can easily set/clear and jump on, which works most of the time, but it obviously conflicts when arithmetic sets it.
>>
>>54675846
Nope because the author added a way to see if fopen succeeded.
>>
>>54675846
it works tho
>>
I'm new to python, and I have a minor problem with my code. I want user input to select a key from a dictionary. I use a while loop to ask the user for a new input if the previous one doesn't exist in the dictionary.
The problem is that some keys have a space or two in the end of their names. How can I select those keys if the user input is the keyname, but doesn't include the spaces? My code this far is basically :
while user_input not in dictionary:
user_input = input("question")
>>
>>54675860
>>54675865
Yeah I'm a bit retarded.
 printf("%s", 5);
is a better example.
>>
>>54675902
we're all retarded down here, Anon.
>>
>>54675856
It has proper hardware support. It's called bit fields and globals.

struct errors {
int e1 : 1;
int e2 : 1;
....
};


>>54675902
That's a fault of the user for not passing in good data. You can check whether what you're passing into printf is valid data.
>>
>>54675924
>That's a fault of the user for not passing in good data.
That's the point. >>54675816 was implying that you deal with that in the function somehow, but in this example it's impossible, as %s tells the type of the corresponding argument, it's not like printf can see that the arg is an int and handle the error.
>>
>>54675951
actually compilers usually give errors/warnings when you do that
>>
>>54671340
Haskell is literally a lambda calculus with some added features. Knowing Haskell means you know LC.
>>
>>54675967
gcc just segfaults (an error that you can't catch ;) )
>>
>>54675967
If a compiler were to error on compiling that code it would be noncompliant. So warnings. GCC doesn't warn you on default settings.
>but its an error
No it ain't:
char * string = "fnord";
printf("%s\n",(int*)string);
>>
>>54675924
>It has proper hardware support. It's called bit fields and globals.
Still not ideal, with a dedicated hw support you could have super tight code like:

call some_func // sets the 'err flag' on error
jerr abort // jumps if 'err flag' is set


Then you could also extend this with a dedicated memory/segment map of strings (basically err_strings
 -> "some string"), and add functions to load in a set of strings (similar to you you load in descriptor tables for example).
So on entry point of a function you could do:
loaderrmap [myerrmap]
// do stuff
seterr 5
ret

// now the caller can jump to an abort function
// abort function can load string 5 from current 'err strings segment' and print it or w/e
>>
>>54675971
geez louise, I like haskell and all but you sound autistic
>>
>>54675399
Wtf is that
>>
>>54676060
a very shitty desktop
>>
>>54676030
I doubt that standard says anything about warning, or even a compiler
>>
>>54676069
I don't understand that sentence
>>
>>54675985
gcc doesn't segfault, the OS does, and every OS worth using has ways of catching segfaults - Windows has SEH, GNU/Linux and posix likes has signals (and they are of course exposed as C APIs).
How else do you think debuggers can stop your program on segfaults?
>>
>>54675951
>>54675902
You're an idiot. You didn't satisfy the precondition of the function, so the function has no obligation to do anything.
/* arr must point to an int array of n elements */
void my_fn(int *arr, size_t n) {
...
}

and you pass it
int arr[2] = {0};
my_fn(arr, 5);

Whose fault is it that the code "doesn't work"? It's the users fucking fault for not passing the correct arguments.

The same applies to all of the standard library function and every function in general.
printf expects a valid pointer to a C string. If you don't pass it that, it's not obligated to do anything. The standard calls that undefined behaviour.
>>
>>54676096
you're right
but there is no way for me to catch such an error in the program

>>54676098
That's my fucking point you mongoloid. Read the entire conversation.
>>
>>54675902
undefined behavior
>>
I have to learn about enterprise java development (no bully pls) for work.

I have no clue where to begin in learning, and my boss didn't give any specific topics to learn about.

Could anyone point me to a good resource on the topic?
>>
>>54676115
That one blue book that says JAVA in yellowish papyrus
>>
>>54676105
>but there is no way for me to catch such an error in the program
Of course there is - you use those aforementioned APIs and setup handlers/signals.
>>
>>54676096
Catching segfaults and then doing anything but crashing the program is retarded. The program data is contaminated when a program segfaults, so doing more with it is asking for corruption.

>>54676105
Yeah you can. Just set the signal handler.
>>
File: 1422357412205.jpg (37KB, 400x386px) Image search: [Google] [Yandex] [Bing]
1422357412205.jpg
37KB, 400x386px
>>54676119
p-please
>>
>>54675985
>gcc just segfaults
your hardware must be buggy, gcc is pretty stable
>>
>>54676147
top kek, you know what I meant (that my program compiled with gcc segfaults)

>>54676145
honestly just make it in your favorite image editor and reverse image search for it, it should come up
I'd add a radial gradient that goes from a lighter blue to a darker blue, from the center out
>>
>>54676138
>Catching segfaults and then doing anything but crashing the program is retarded. The program data is contaminated when a program segfaults,
Not necessarily.
A segfault due to an access violation (like trying to write to a page without write access) is no problem recovering from for example.
>>
File: img.jpg (56KB, 407x500px) Image search: [Google] [Yandex] [Bing]
img.jpg
56KB, 407x500px
>>54676163
is it this one?

i am already reasonably familiar with java, and I need to learn about java EE stuff in particular.
>>
>>54676183
no, not that one
Also, in that case, I don't really know; I never read the book I'm talking about, nor have I effectively learned much java (beyond syntax/OO/etc)
>>
>>54676173
I suppose but any situation where you can reliably ascertain the cause of the segfault and also know that it's safe to continue is very contrived. It's also easier to implement a non-ghetto fix most likely.
>>
>>54676145
I think he's talking about Introduction to Java Programming 10th ed by Y. Daniel Liang. I've seen it recommended before, but I'm not sure how good it is.
>>
>>54676145
>>54676163
i image googled "blue java book", had to scroll down a bit but it was there

>mfw "blue waffles" is the top suggestion, above "blue", when you type in blue

>>54676183
daniel liang
>>
>>54676173
>no problem recovering from
how do you recover from it? do you realize that a segfaults means your program is buggy? how can you revert to a consistent state after the segfault?
>>
>>54676221
You setjmp before the hairy code and when it segfaults you longjump and go down a different branch. This only works if you know that the hairy code isn't going to corrupt your program data (i.e. dereferencing null pointer).
>>
>>54676221
>how do you recover from it?
Depends on what the function was doing of course.
But say an out of bounds access where you guarded the buffer with no-access pages on both sides you can just silently let the program continue if you want.
>>
>>54676173
Even if it's a "safe" segfault, your program may still be in an inconsistent state.
Say you're in the middle of updating some structure, and you segfault. Now your structure is in an inconsistent state.
>>
i don't get it, why is this /dpt/ tab using 285 MB memory and a sizable amount of CPU time?
>>
What's the [spoiler]best[/spoiler] and [spoiler]simplest[/spoiler] language for a [spoiler]basic text based game[/spoiler].
>>
>>54676295
ad block and other addons
>>
>>54676252
>just silently let the program continue
how do you know the state of the program you fucking monkey?
>>
>>54676310
i'm only using ublock origin
>>
>>54676297
You all are the same.
Python is good for that. There may be slightly better options but if you're parsing simple commands and whatnot, it's easy with Python
>>
>>54676265
>Say you're in the middle of updating some structure, and you segfault. Now your structure is in an inconsistent state.
You will now the address of where the exception occurred, so you can jump back to anywhere in that function where you have a path which sets the struct to zero or some default or error state.
It's no different that if you say checked return value of malloc and then wanted to still return a sane structure, but with some pointers or null or w/e.
>>
>>54676333
Give a code sample and I'll show you why your solution is retarded.
>>
New thread: >>54676367
>>
>>54676322
Because you are the one who setup the exception handlers.
If it was an access violation, you can check which address it tried to access, if it was your guard pages you know it was just an out of bounds read or write and you can make the function just return a default value (if it was a get-like function), if it was writing something you possibly don't have to do anything, might just log it)
>>
>>54676366
Do you know how structured exception handlers work in Windows?
What state is it that you don't think one will know?
>>
>>54676401
Show a code sample. You don't understand the purpose of SEH.
>>
>>54676414
I know them perfectly well.
>>
>>54676426
Why don't you show a code sample?
>>
>>54676439
Example of what?
>>
>>54676444
Of how you intend to recover from a segfault.
>>
>>54676066
Pretty sure that is a laptop.
>>
>>54676454
Not him but
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
jmp_buf b;
void foo(int s) {
longjmp(b, 1);
}

int main() {
signal(SIGSEGV,foo);
char * c = 0;
int i = setjmp(b);
if(i == 0) {
printf("fnord\n");
*c = 1;
}
printf("we fine\n");
}
>>
>>54671340
>calls haskell users pretentious
>brings up fucking lambda calculus
And on today's episode of "shit no one cares about"...
>>
>>54676530
wrong
>>
>>54676562
It works on my machine.
$./test
fnord
we fine
>>
>>54676530
>Not him but
Good, because you're fucking retarded. We're talking about real world code, not fizzbuzz tier.
>woooo, here I deref NULL and I catch it
What is the point, you fucking idiot, if you know the exact assignment that segfaults? If you know it segfaults, why are you doing it anyway? Are you fucking mentally ill?
Show me code like
here_we_setup_handler();
here_we_call_risky_function();
here_we_recover();

How the fuck do you know WHERE the "risky function" crashed? How do you know what part of the state it changed and what didn't get to change? How do you know what locks are still held? Are you this dumb?
>>
>>54676608
So angry.

Let me leave you with a quote:
>I think that it's extraordinarily important that we in computer science keep fun in computing. When it started out, it was an awful lot of fun. Of course, the paying customers got shafted every now and then, and after a while we began to take their complaints seriously. We began to feel as if we really were responsible for the successful, error-free perfect use of these machines. I don't think we are. I think we're responsible for stretching them, setting them off in new directions, and keeping fun in the house. I hope the field of computer science never loses its sense of fun.
Please consider what this quote means and how it relates to my segfault recovery post, as well as the endianness hack for turning a char into a string from last thread.
>>
>>54676664
>Let me leave you with a quote
In other words, you don't know what the fuck you're talking about.
>>
>>54676426
doesn't look like it, m8
>>
>>54676763
I'm pretty certain I do. I'm talking about fun.
>>
>>54676784
Yes, you're just a moron.
>>
>>54676800
This is not a developer's conference my friend. If you want serious bsns you should probably go to one of those instead of /dpt/. I will continue to have fun.
>>
>>54676814
>so what if I'm a retard
>>
>>54676814
>I'm allowed to spew inane drivel on muh animu subreddit
anon...
>>
>>54676834
If having fun is being retarded then I wanna be retarded.
>>
>>54676454
#include <windows.h>
#include <excpt.h>
#include <stdio.h>

extern void goto_addr(void *);

static void *saved_addr;

static DWORD NullPtrFilter(LPEXCEPTION_POINTERS ex)
{
DWORD code = ex->ExceptionRecord->ExceptionCode;
if (code != EXCEPTION_ACCESS_VIOLATION)
return EXCEPTION_CONTINUE_SEARCH;

saved_addr = ex->ExceptionRecord->ExceptionAddress;
printf("instruction at %p tried to write to null\n", saved_addr);

return EXCEPTION_EXECUTE_HANDLER;
}

int main(void)
{
__try {
*(int *)0 = 7;
puts("hello"); // +11 bytes on x64 and this compiler, you might need to change it
ExitProcess(0);
} __except (NullPtrFilter(GetExceptionInformation())) {
puts("don't write to the null pointer!");
}
if (saved_addr)
goto_addr((char *)saved_addr + 11);
}

// goto_addr
.code
goto_addr proc
jmp rcx
ret
goto_addr endp
end


Calculating the correct recovery address without hardcoding (i.e the code the execute after the write to null) requires some form of injecting marker code, which could be a call to a no-op function and then searching for that call in the machine code and use that as the continuation address.
>>
>>54676942
This thread is beyond dead man. You might wanna crossquote yourself in the new one so who you're responding to sees it.
>>
>>54676942
>fizzbuzz
fuck off
>>
>>54677046
>moving goalposts
You said an example, you got blown the fuck out.
I never said this was practical or something you should do, only that you could do it.
The most sane thing to actually do for real on segfaults is of course just to optionally log and exit the program.
>>
>>54674427
Duane!
>>
>>54677087
>backpedaling
top cuck
Thread replies: 355
Thread images: 27
[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.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK