[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
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: 43
File: fp.png (243 KB, 810x763) Image search: [Google]
fp.png
243 KB, 810x763
Previous thread at >>51543878

What are you working on, /g/entoomen?
>>
File: muh monads part 2.png (16 KB, 597x285) Image search: [Google]
muh monads part 2.png
16 KB, 597x285
>>
>>51547562
What the fuck kind of bastardized language is this? Why is there code in those strings? Is there some kind of runtime compile system or something compiling that in the background?
>>
>>51547622

template Monad(string Bind, string Unit, string Extra)
{
class M(T)
{
public:
this()(T X) { mixin(Unit); }
mixin(Extra);
}

static auto bind(alias S = x => x, T)(auto ref M!T X) { mixin(Bind); }
}
>>
>>51547562
Second, also what is that exactly?

F#?
>>
>>51547562
language?
>>
>>51547562
>>51547665

FIRST FOR D
>>
File: Captura.png (19 KB, 709x463) Image search: [Google]
Captura.png
19 KB, 709x463
>>
>>51547700
is there any problem with this piece of code?
>>
>>51547680
>>51547694
>Xamarin Studio External Console
>>
File: b-but muh haskell.png (7 KB, 709x159) Image search: [Google]
b-but muh haskell.png
7 KB, 709x159
>>51547734
Xamarin is the best IDE supporting D imho
>>
has realtalkintech been confirmed for /g/? or is there a possibility that hes for real
>>
>>51547734
>Xamarin Studio External Console
That's not a language m8
>>
>>51547747
Visual D.
>>
>>51547747
Neat. Did not know Xamarin supported D..
>>
What database should I use for Node.js? I'm thinking MongoDB..
>>
>>51547797
It's not built in, but it's easy to install

Main thing you need is DMD (official compiler & library implementation)
>>
/dpt/ - D Programming Thread
>>
mixin is the feature every language needs
>>
I want to make a multiplayer game as a project with my friend. What networking library should we use?
>>
I know I suck cocks at programming and all but:
        for (String s:someArrayListOfStrings) {
if (s.charAt(s.length()-1) != '/') {
s = s.concat("/");
}
}


Reassigning the elements to one with / concatted in the foreach loop doesn't seem to actually do anything to the objects contained in the ArrayList. What am I doing wrong? Is s not a reference to the object stored in the arrayList?

java btw
>>
File: error.png (262 KB, 1440x900) Image search: [Google]
error.png
262 KB, 1440x900
posting error code.
>>
Guys, what are your toughs on Multi-threading Programming?
>>
>>51547869
Second this
>>
File: rss.jpg (84 KB, 1577x407) Image search: [Google]
rss.jpg
84 KB, 1577x407
I'm trying to write a bash script that will daily, check to see if there's a new podcast episode posted on a certain website caching server. If it's newer than the one I have downloaded, then wget it, to my directory.

pic related: it's a piece of what i'm writing
>>
>>51547490
kill yourself
>>
>>51548027
Why are you including print statements? Presumably you plan on running your script in the background as a cronjob, no?
>>
>>51547913
Not sure about java, but re-assigning the loop variable in a for each loops doesn't work in C#.
>>
>>51547971
Its modern message passing concurrency not taught in CS curriculum because everyone expects that people are going to fall back on semaphores. Most programmers dont understand multi-threading and have stupid ideas like you can break up a program into 6 threads and it will run 6 times as fast. The truth is most programs depend on previous instructions so that programs are forced to run linearly.
>>
>>51547913
s is a copy of the element in the array list. You should do a for loop over the indices in the array list so that your last line reads something like

 someArrayList[i] = someArrayList[i].concat("/"); 
>>
>>51548135
It should work fine depending on what you're doing. Don't add or remove elements for example but just modifying what they point to shouldn't be problematic. That wasn't the problem. foreach loops are fucky and bascially, on an arrayList, perform a get operation on the arrayList and assigns it to s.

I then modified s, which doesn't change what the arrayList refers to.

Since I'm converting it to a regular array anyway I converted it a step earlier and did the typical for (int i = 0; blah blah) iteration over it instead.

I might just never use foreach loops again. I always have problems with them and all they do is save writing thingyArray[i] over and over.
>>
>>51547913
In Java you're only editing on a copy of the pointer. If you want to operate in-place you need to either do a manual loop (for int n = 0; n < array.length.........) or write a very verbose iterator.

THE MAIN REASON IS THAT STRINGS IN JAVA ARE NOT MUTABLE. THERE IS NO WAY AROUND THIS.
>>
>>51548174
I just realized that the syntax is wrong (my Java is rusty), but the basic idea is right.
>>
>>51548197
Yeah I know strings are immutable I just didn't know s was a copy of the arrayList's pointer instead of being the pointer itself.
>>
>>51548218
Yep as a rule of thumb, if you're ever reassigning a variable that you declared in a function (not a field in an object, just a variable such as "x = 2" or "s = s.concat(...)"), you are ONLY MODIFYING THAT VARIABLES VALUE. You are not modifying any property of any object anywhere or any member of any list or anything, and you aren't modifying any variables other than the variable in the assignment.

It's a little bit trickier when you're assigning a field
class Foo {
private x;
void thing () {
x = 3;
}
}

But a good way to think about this is that it's actually just "this.x = 3", and that "x = 3" is just a shorthand for doing the "this" thing.
>>
Please don't tell me D fags are the same guys who cry about how convoluted and complex C++ is
>>
>>51548265
>that it's actually just "this.x = 3", and that "x = 3" is just a shorthand for doing the "this" thing.
QA people would probably reject this code because it makes it less clear on scope. If what you mean to modify is the class member then just use this keyword even when there's no other variable to get confused about.
>>
>>51548113

The printf's are there just for testing and IF I want to convert it to a scrip that I can run manually.
>>
>>51548316
>use this keyword even when there's no other variable to get confused about
I suppose that's a good convention to follow but I don't personally follow it in languages like Java, C# or C++.
>>
>>51548292
why do you think D was named D?
>>
any book recommendation on express and angular?
>>
>>51548437
mixin doesn't always return

for instance

mixin("struct S { int x; int y; }");
>>
>how you want your macro system family?
>I can do the preprocessor, template, or exposed AST
>just compile my strings up
>>
>>51548158
I was one of those people, until we had a class about that, we separate 1 program in 2 and 3 threads, the "speed" barely increase.
>>
>>51548158
>>51548537
What kind of bare bones applications are you writing that are actually that I/O bound?
>>
File: 1446146233623.jpg (409 KB, 4288x2848) Image search: [Google]
1446146233623.jpg
409 KB, 4288x2848
>>51547913
Java has no one-liner to accomplish that. Not even in the latest version, which is 8.
The object-oriented solution to your problem is as follows:

import java.util.Arrays;
import java.util.List;

public class Main {
public static void main(String[] args) {
List<String> derp = Arrays.asList("amd","intel","nvidia","samsung");
Mapper.map(derp, new Mapper<String>() {
public String handle(Integer index, String element) {
return element.toUpperCase();
}
});
System.out.println(derp);
}
}


and the helper class

import java.util.List;

public abstract class Mapper<T> {
public abstract T handle(Integer index, T element);

public static <U> void map(List<U> array, Mapper<U> m) {
for(Integer n = 0; n < array.size(); n++) {
array.set(n, m.handle(n, array.get(n)));
}
}
}


To summarize: you have to create a helper class for both iterating over all list elements as well as providing an interface for your string operation (s.concat or whatever). Then you must instantiate a new Mapper object and provide a handle() method that does whatever you want with each element. I added the index Integer for shits and giggles, but it is unused. The <T> and <U> stuff is to ensure that you can re-use the Mapper class for every kind of list (strings, integers, floats, even your own custom classes). This is actually a very common design pattern in all of Java and can be seen in other classes like Calendar, Comparator, Sets, and Bytestreams. It's not like there's no other way to solve this - it's that Java (and OOP) was INTENTIONALLY designed this way.

Welcome to Java. Enjoy your bloat.
>>
Any fellow Indians here?
>>
>>51548197
what about scala strings?
>>
>>51548714
I have never used Scala so I can't comment on that matter.
>>
>>51547724
not only one
>>
>>51548714
http://lmgtfy.com/?q=are+scala+strings+immutable
>>
File: indians.png (18 KB, 786x212) Image search: [Google]
indians.png
18 KB, 786x212
>>51548677
the stereotype is just a minority
right?
right?
>>
>how do we prevent string literals from being modified? this will let us share identical literals
>why not add "const" like C or C++?
>good idea, that will also allow other objects to be made immutable if the programmer wishes
>NAH GUYS LET'S JUST MAKE THE STRING CLASS IMMUTABLE EVEN IF IT'S NOT A LITERAL
>excellent idea Johnson
>>
>>51548820
The irony here is that mutable strings are the #1 top googled C segmentation fault error message.
>>
>>51548906
Blame C for not forcing string literals to be const
>>
>>51548820
>how do we prevent integers from overflowing? this will let us share safe integers
>why not add "unsigned" like C or C++?
>good idea, that will also allow other numbers to be made unsigned if the programmer wishes
>NAH GUYS LET'S JUST MAKE THE INTEGER CLASS SIGNED AND REMOVE ANY AND ALL UNSIGNED TYPES
>excellent idea Johnson
>>
>>51548921
but muh backwards compatibility
>>
>>51548959
god dammit, Johnson!
>>
>>51548600
>What kind of bare bones applications are you writing that are actually that I/O bound?
I never said anything about I/O, I/O is not the issue preventing programs from being parallel. What is preventing parallel programming is that most programs you use from day to day are doing a simple task that cannot be broken up into smaller tasks. An easy example is a text editor, it just sits there and waits for you to push a key and then it does something. There is no parallel programming that can speed that up.
>>
>>51549248
>An easy example is a text editor, it just sits there and waits for you to push a key and then it does something.
Is that not I/O bound? Maybe not in the typical sense where you're waiting on the disk, but still...
>>
>>51549295
ok, well even if you eliminate programs that dont wait for keystrokes, most programs I can think of are made to do a simple task and only one task at a time. Even the graphical interface for those programs cant be made parallel because the interface is waiting for the single threaded program to tell it what to do.
>>
Can I get some help on this? Trying to parse a string of numbers that can be formatted in the form x,y,z or x, y, z, however, when the spaces are added, it ignores everything after x.
while(stream >> n) //reading input
41 {
42 numbers.push_back(n);
43
44 if(stream.peek() == ',' || stream.peek() == ' ')
45 {
46 stream.ignore();
47 }
48 }

Sorry about line numbers, yanked directly from vim.
>>
>>51549489
What type is 'n'?
>>
>>51549522
int
>>
>>51549522
and numbers is a vector of ints
>>
>>51549489
In the case of
x, y, z
, you have two junk characters between the numbers you wish to read (',' and ' '). So what you may want to do is change that inner if-statement to a while-statement to keep dropping junk.
However, when I run your code with g++, I get all the numbers as expected, so not totally sure.
>>
Would anyone recommend this book? It got good reviews on Amazon
>>
>>51550169
Yeah I loved it. Great read and a nice reference piece too.

I also really enjoyed the Stanford Coursera course on algorithms
https://class.coursera.org/algo-004/lecture
>>
>>51550210
Sweet, I just ordered it.
>tfw $10 off and free two-day shipping thanks to based Prime
>>
>>51550169
Yes, it is a really good book to use as reference.
>>
>http://www.extremetech.com/computing/182428-ironic-iframes-adblock-plus-is-probably-the-reason-firefox-and-chrome-are-such-memory-hogs
holy shit this is cancerous. a lot of website have really cancerous ads but shouldn't there be a better way to block ads? my gjewgle chrome slowed down to beyond retardation (despite having 700 MB RAM available according to the task manager) and i tried disabling adblock and it seems to have helped a bit although it won't recover fully until i've restarted my browser/computer or at least refreshed each tab
>>
>>51551010
these last months, the media has been pushing against ad blockers and encryption... journalists don't know shit about technology, so you have to wonder if these are concerted attack from certain companies and political groups, or something.
>>
>>51547918
>libGDX

garbage
>>
I'm working on a softbody dynamics simulation in C++ and opengl. The rendering is good enough. Working on physics unit test by unit test
>>
>>51549489
Try changing the 'if' to a while
>>
>>51551010
Protip: It's not true.
You really think people who make money from adverts are going to be like "Yeah adblock is great"
>>
>>51551084
>>51551229
adblock has been using like 260+ MB RAM for me though. and maybe it adds even more on each tab?
>>
>>51551262
and google chrome runs fine for like a day or two and then it gets worse and worse until it's barely usable.
>>
>>51551270
wow ads are extremely cancerous. switched forcus to a tab, went up 5,5 MB. refreshed with adblock disabled, memory usage went up 49 MB...
>>
File: 1352344718582.png (13 KB, 180x195) Image search: [Google]
1352344718582.png
13 KB, 180x195
Hello /g/

I'm a beginner at coding (java) and I'm trying to make a class extend JPanel and then add a JButton to the panel. how can i do this? if I just type
JButton retry = new JButton ("retry");
add( retry);
I get an error message I cant solve.

Also how do you post code in the picture area like above posters?

Thanks
- T. Newfag
>>
>>51551640

>I get an error message I cant solve
Why do you think it is okay to ask us for help, telling us you have an error message, and not tell us what that error message is? Do you think we are some sort of group of magical hackers who can see what is on your screen at any given time? What do you think this is, some kind of mosaic.wav song?
>>
so uh if i understand this correctly
directx uses row-major matrices for operations (World * View * Projection) and column-major for storage
HLSL uses column-major for operations(?), meaning i have to transpose the final matrix in directx before sending it to the GPU right?
im surprised shit like this havn't been standardized after all these years
>>
>>51551749
I figured you might know how to do it correctly and I would just figure it out from there, instead of burdening you with solving all of my problems.

I'll be more specific next time so I don't confuse you, tripfag. I fixed it anyway, you can disregard the request,

I also read the sticky so you don't have to answer the second request either.
>>
>>51551801
np vulkan coming soon
>>
>>51551804

>I'll be more specific next time so I don't confuse you, tripfag
It's generally a wise idea to provide a decent amount of information when requesting for help, especially since it is likely to lead to...

>I fixed it anyway, you can disregard the request
solving your own problem before posting, or very soon after posting.
>>
>>51551868
Yeah...I just said that.
>>
>Trying to be comfy coder at work
>End up being DBA for 75% of my day
>DBAing a database designed by code monkeys.
Fuck.
What's /dpt/'s opinion on SQL anyway? Does it count as programming or not?
>>
>>51551931
Adding to why the db is made by monkeys:
>MS SQL Server
>GUID primary keys everywhere
>Clustering on primary keys everywhere, everything is newid() not newsequentialid()
>No database level foreign keys anywhere, all done manually
>Using separate databases instead of schemas
>Holy random text collation rollercoaster batman
>nvarchar(max) everywhere, even when nchar(4) would be acceptable
>Every application and developer uses a god-access account, even on production (at least it's not sa).
>>
File: 20150913180421.jpg (46 KB, 960x538) Image search: [Google]
20150913180421.jpg
46 KB, 960x538
>WHY WON'T YOU PROGRAM IN COMMON LISP AND MAKE BETTER LIBRARIES FOR IT ONIIICHAN
>>
File: Untitled-1.png (140 KB, 1190x2354) Image search: [Google]
Untitled-1.png
140 KB, 1190x2354
>>51551931
>What's /dpt/'s opinion on SQL anyway? Does it count as programming or not?
Considering you can write sudoku solver in SQL, it definitely has the potential.

Most often though, it's more of a data query language than programming language.

Doesn't meant you shouldn't post your SQL stuff here, of course.

Picture related. Postgres query explanation for one of bigger queries I wrote yesterday.
>>
>>51552037
ahhhh my eyeesssss
>>
>>51552051
There's no better way. Or at least the way I understand it.
>>
>>51549436
You should be running i/o in a separate thread.
>>
>>51551931

Terrible understanding of SQL is one of the major reasons so many apps don't scale.

>Sysadmin
>Developer demands faster serve
>Code looks absurd, so I profile it
>950+ SQL queries on the fucking landing page
>Discuss concerns
>Developer has solution
>"We'll buy SSDs"
>>
>>51551801
pls respond
>>
>>51552031

Most of the time, when I want to use a Lisp, I use a variant of Scheme called TinyScheme. It's main usage is embedded programming. Of course, since I've discovered just how hackable mruby is, I have not been playing with TinyScheme as much.

With regards to Common Lisp, I've tried learning it a few times, but it just feels kind of awkward compared to Scheme, and when I look at the grand scheme of things, it doesn't fit a use case that the languages I already know cannot fit easily, nor does it have many libraries that would make it stand out and have a niche.

But why aren't YOU writing libraries for Common Lisp?
>>
>>51552119
I/O is handled by the OS not the programming language, programming language I/O functions are just wrappers to syscalls
>>
File: C.png (136 KB, 2000x2126) Image search: [Google]
C.png
136 KB, 2000x2126
>>
>>51552549

What he is suggesting is that if some section of code is making syscalls related to I/O, it should be done in a separate thread. It would be very shitty for the user to press on a button and have it not respond because that thread is currently in the middle of some heavy computation. It would also suck for the computation to have to be stalled until the user does some input.
>>
>>51552735
thats overkill to spawn a thread just to wait for a file to open, its better to just use callbacks
>>
>>51552798
You don't have to spawn it, you can already have it running.
>>
>>51552798

Honestly, it depends upon the I/O used. The practice of spawning new threads for I/O is typically done with things such as, say, a UI or network traffic. Interestingly enough, on Android, if you try to do network stuff in the UI thread, the OS will bitch at you and crash your application.
>>
>>51552798
you ever try to click on a window while I file open dialog is open?
DING
DING
DING
DING
I even changed it to a relaxing wave crashing on beach sound, and now the mere sight of beaches and waves makes me ANGRY.
It's like a less irritating form of your printer, which grinds gears against eachother every startup for some reason.
>>
>>51552870
I/O in Android is a joke, you cant directly access system I/O, just make broadcasts and listeners
>>
>>51552279
jesus christ tell me this was made up in a fake scenario to explain retardation
>>
File: 1343389455826.jpg (102 KB, 620x916) Image search: [Google]
1343389455826.jpg
102 KB, 620x916
C++ time.
say, guyise, i have a vector of virtual bases(of gui elements, for example) and those bases are actually concrete elements that can have various methods that allow you to interact with them. how would you provide these methods to the end-user who get an element as a base pointer from the object that stores the vector?

now, i can imagine two ways- manually casting pointer class or providing virtual bases for absolutely every setter that throw an error, therefore throwing whenever there's no overload. and both feel shitty.
>>
>>51552913

Not only is it completely not made up, it's also only half the story.

When the SSDs didn't do shit, I presented a paper to management showing them I'd traced the issues, and the fact that even Google bot hitting the site ran this triple nested query bullshit to generate a table.

Management took it to the developer and came back with the solution: I would install Redis, which is great for caching.

So I installed Redis. And they made absolutely no changes to the codebase refused to believe they actually had to do something to make Redis useful.

They subsequently posted on reddit, wherein /r/webdev advised "your sysadmins musn't know what they are doing. If they did, you would purchase a cloudflare business plan". So they did.
>>
>>51553021
Fuck I'm so sorry dude, maybe in another life you wont have to work with Pajeet and Rajesh.
>>
>>51553021
The state of the industry, ladies and gentoomen. Milking as much money as possible on bullshit.
>>
>>51553042
Actually their names are Pooja. Both of them.
>>
>>51553050
OOL EHT NI OOP
>>
>>51553049
I don't think thats something normies can avoid however I think the problem is that these paid (and probably qualified) developers that should understand the basic concept of dataflow and where a bottleneck occurs.
>>
post links to new thread
>>
File: ayyyyy.webm (2 MB, 450x515) Image search: [Google]
ayyyyy.webm
2 MB, 450x515
I spent ten hours trying to fix a problem only to give up when my solution didn't work.
When I reverted to the old method, I then found that one of the trivial changes in some other section of code I had made to facilitate the new method must have fixed it, because now it works golden.
Before, the hallways in maps above 120 units in size looked like a swarm of dead insects in a spider web.
Looks better now, layouts actually make sense.

This means, of course, that I am literally finished with the map generation for now, and can start working on the computer exploration module.
>>
File: ZuqqFk1.webm (713 KB, 404x404) Image search: [Google]
ZuqqFk1.webm
713 KB, 404x404
Ask your beloved programming literate anything.
>>
>>51553163
nice cat
>>
>>51553163
how long will humanity last
>>
>>51547490
>What are you working on, /g/entoomen?
It's not pretty, but it works
https://gist.github.com/anonymous/a2c464bfdecde5e0da28
I ported interjection.pl to python for https://github.com/infinity-next/
>>
>>51553213
Mate that code was painful to read.
>>
>>51553163
Are you aware of the urban myth (that has some mild scientific backing) that feeding your cats spinach will result in them getting kidney stones and piss crystals, potentially killing them via infection?
>>
>>51553170
>>51553188
>>51553254
not programming
>>
>>51553007
Need more information. How is user interacting with those objects? Who is user anyway? Programmer who is using you library? A normal person who is using the program you wrote?

Former is the right way here, but since you feel bad about it, maybe you're doing something incorrectly.
>>
>>51553142
use local git repo anon. it makes catching bugs that you have introduced through mistype or other silly errors super-easy.
>>
>company wants multi language support
>language variables
>language variables everywhere
>>
File: ss+(2015-11-27+at+01.37.38).png (74 KB, 788x684) Image search: [Google]
ss+(2015-11-27+at+01.37.38).png
74 KB, 788x684
>>51553142
Oh, there you are.

Trying to do something similar to what you're doing.

But I'm thinking of also using perlin noise to generate connections between caves.
>>
i thought it's ask me anything
>>
File: 1448620490373.jpg (20 KB, 1024x231) Image search: [Google]
1448620490373.jpg
20 KB, 1024x231
I need to make a site authentication so you can't use a page on a site without being logged in. What is the best way to do this? I'm currently trying to make a token, but it doesn't seem to be that easy.
>>
>>51553419
neato.
If I have one suggestion, try playing around with making expansions and contractions of your cells take place in separate frames.
Actually, no contractions: just apply an expansion rule, but to the floor instead.
I found that it ends up working way better than doing them both in the same step, like traditional automata.
then just play around with adjusting each of these one at a time and seeing how they play off of eachother.
>>
>>51553462
The way I did it was by having a data structure that stores a person's username, ip address and user agent. If you're in the structure, you're logged on.
>>
>>51553494
Could you explain this a little more? Like what programming language did you use? Is there a link online which could help me understand this?
>>
>>51550169
I read parts of it related to sorting, it was well written that's about it.
>>
File: Untitled-2.png (10 KB, 1188x396) Image search: [Google]
Untitled-2.png
10 KB, 1188x396
>>51553467
Ah, yes, I am doing that.

Working on each layer separately and then just overlaying them.

Although after working on those layers for a while, I think the best solution for me would be to let user define the whole algorithm using some visual flowchart-like thing. Nodes would be operations, like generate noise, expand/contract, merge, etc and connections would be half-done maps passed around between nodes. Seems like a massive effort, but I believe it will be worth it in the end.
>>
>>51553551
we'll both be drafted or nuked before either of us finish.
>>
>>51553555
Please don't say that.
>>
>>51553502
I use C#.

I have a data structure, a dictionary of two strings to be exact.
Answering a captcha correctly adds you to a dictionary with the key as the concatenation of userip and user agent
The value in the dictionary is the username, but without "logging" in the username is anonymous

After you login, that is if the hash of the hash of your password is equal to the double hashed password (yeah I know) as stored in the database, it replaces anonymous with the actual username.

Whenever a user connects I check to see if their ip and user agent is in the database, if so I get their username and check their privileges, if they're anonymous or have insufficient privileges I return a 403. Otherwise, if they're not even in the database I return a 401. Lastly, if everything checks out I 200 and return the resources they requested.

Using my own hashing algorithm, so I can hash the same way on my website as in my database. I'm using a massive salt, so I doubt anyone would spend the time creating a rainbow table.

I might post code next if you're still not getting it, but be warned I'm that guy who wrote his own framework, so unless you want to use a library called "FAP"...
>>
>>51553577
Ow, I was actually looking for something more web-based
>>
>>51553342
i would ideally want to
struct Test
{
virtual Test* get_derived() = 0;
};

struct Test1 : Test
{
virtual Test1* get_derived() {return this;}
void Lol() {}
};

Test* test = new Test1;
test->get_derived()->Lol();


however covariant return doesn't work that way. and i wouldn't wanna add serialization just so that programmer doesn't have to manually cast objects whenever he wants to modify them.
>>
>>51553577
What if two people using same browser inside same mobile network connect to your site? Will the second one be logged in as first?
>>
>>51553634
If programmer wants the Lol function, he knows he's working with Test1 class. So in this case, his variable definitely should have type Test1 *, not Test *.

Also get_derived function is kind of nonsensical. It would return this always. You don't need it.

So the way I see it, code would look something like this:

QList<Test *> items;
(...)
Test1 *item=(Test *) items[999];
item->Lol();


Doesn't look that bad to me.
The only problem is how to ensure that the item you're working with is actually Test1 and not something else. In Qt and Borland, you have built-in reflection, so that's easily solved. Outside of it, I believe you'll have to come with at least some form of reflection. And the fact that Qt and Borland people did invent their own form of reflection, means that there's really no way around this.
>>
>>51553603
You absolutely cannot create a login system without a backend, that would be insanity, you could defeat the system just by reading the js code. Look, my captcha verification code is 12 lines of code is it worth turning on my computer for?

These kind of things are actually so simple I don't think anyone has bothered to write a guide for it. Compare hashes and add to a session data structure, quick dirty and easy.

>>51553639
Within the same mobile network they have different ips, so its all good.

Behind a private network they have the same ip and so if they're using the exact same make of browser, including the same os, there'll be caching issues first and second there'll be session issues. The second guy will be basically stuck on the login view and get a lot of 403 errors.

For EXTRA SECURITY I implemented a sort of token system, the second guy will basically have an incorrect session number. In hindsight this isn't as useful or as secure as I thought it would be (because the token sequence is the same each time), but it's already done so whatever.

If I could be really fucked I'd add the day of the year to the hashing sequence, so the hash is different every day you login (but still predictable on both ends). I can't be fucked and if you're worrying about more than just a kid running wire shark you have issues.
>>
>>51553007
How about:
struct Parent
{
template <typename T>
T *as()
{
return dynamic_cast<T>(this);
}
};

struct Child: public Parent
{
};

Base *ptr = new Child{};
ptr->as<Child>()->something();
>>
>SICP or the art of computer programming

better one?
>>
File: 1422905827890.jpg (50 KB, 1280x720) Image search: [Google]
1422905827890.jpg
50 KB, 1280x720
>>51553692
but we have virtual function table in c++, so when i call get_derived() this little shit knows exactly which get_derived() i want. therefore it knows to what type i wanna cast this. why do i need to specify ONCE AGAIN that i want the derived class, when it could just give me derived through virtual function table and simultaneously rid us of dynamic_cast<>?
>>
reddit is easy to use, you don't even need an email to set a login in 2sec
>>
File: ebinfug.png (51 KB, 1646x822) Image search: [Google]
ebinfug.png
51 KB, 1646x822
So, I literally started my programming learning few days ago. I went straight to C++.

I made a program, that converts temperatures.

It converts the selected type of temperature to the unselected ones.

First it asks you to choose the type, then it asks the question again to confirm, after the comfirmation it jumps to the conversion, you enter the value, it does the conversion, after that it asks you, if you want to redo the conversion, jump to the beginning or exit the program. Pic related, that's what's happening. Ite does the same for all the temperature types.

I noticed few things:
>It became pretty long for such a simple program
>I used goto. I heard that you should never use it
>You need to actually enter the numbers and press enter, instead of reading the keyboard input straight
>And so on....

So:

Tips, tricks, corrections, simplifications? Also I'd like to know where to go from here, or how to extend this project to be more advanced.

I suck balls at this, and I'm a total newfag to programming in every aspect, since C++ is the first language for me.
>>
>>51553887
What the fuck are you naming your variables? And people said I picked bad variable names...
>>
>>51553887
Is that a screenshot of your code?

Please, for your own sanity, have sensible variable names. If you ever come back to this code after a while away from it, you'll thank me for telling you this.

There's nothing wrong with using goto, but usually there are better ways to structure your code.

You can use something like Readline to read things as they're being typed.

You can also omit the {} around if blocks that only contain one statement.
>>
>>51553887
is this bait?

-variable names are shit
-you can << after endl. endl literally means <<"\n"<<std::flush
-do not use goto
-read up on switch statement
-read up on classes
>>
>>51553887
>I went straight to C++.

Good choice, my man.

You've made a bunch of fuckups, like
while (jalkikysmys = 1)
.

And just make variables in English instead of Mongolian or whatever that is, it'll be easier for everyone.
>>
>>51553938
Well, that's true. They are in finnish for some god forsake reason. I'll just use english from here on.
>>
>>51553952
also use can post your code with code /code tags
>>
Hey guys. I'm working on a python script which loads a SGM file. There is a long text inside which I need to pass to a bash script and retrieve the results. The bash script is on remote server to which I have an access via ssh.

How do I execute the remote script, pass the data and retrieve results from within a python script?
>>
>>51553770
>but we have virtual function table in c++, so when i call get_derived() this little shit knows exactly which get_derived() i want
That much is true.

>therefore it knows to what type i wanna cast this.
But this is false.
Virtual functions have fixed return type.
The whole virtual stuff is resolved at runtime. When you are looking at code that calls a virtual function, you do not necessary know which one will be called - it is decided at runtime. But everything related to types only lives at compile time. So you can't benefit from virtual functions this way.

Looking closely at your code:
virtual Test1* get_derived() {return this;}


Should be:
virtual Test* get_derived() {return this;}


When you do
Test* test = new Test1;
test->get_derived()


Compiler expects return type of that to be Test *, because you're working with an object of type Test *, and get_derived is defined to return Test * for it.
>>
>>51553887
A good way to use your program more readable is to group code into logically independent parts using functions.
>>
>>51553887
First thing you should do is work on removing repetition. You have almost completely identical heaps of code. There is never a situation where this is a correct and proper solution to a problem, to just copy paste heaps of code.
>>
>>51553997
actually it compiles. look up "covariant return types". it just returnes base when called from base.


so is this the best we can do for storing different types in a vector and downcasting to perform modifications, without bringing serialization in:

struct GUIStorageObject
{
virtual GUIStorageObject* Clone() = 0;
virtual GUIStorageObject* Get() = 0;

virtual ~GUIStorageObject() = default;
};

template<class T>
struct GUIStorage : GUIStorageObject
{
void setValue(T value) { m_value = value; }
T value() const { return m_value; }

GUIStorage<T>* Get() { return new GUIStorage<T>; }
GUIStorageObject* Clone() { return new GUIStorage<T>; }

private:
T m_value;
};


this shit trips my autism so hard.
>>
File: 1431065947020.jpg (315 KB, 960x1280) Image search: [Google]
1431065947020.jpg
315 KB, 960x1280
>>51553969
Alright, I'll just that in the future.

>>51553926
So, here's what I've picked up:
>Variable names are shit. I should use english instead of my native language
>Goto should not be used. I'll stay away from it.
>I'll need to read up on switch statements and classes
>Use "\n" and std::flush instead
>Use readline to read things as they're being typed

What else?
>>
>>51554046
>Alright, I'll just that in the future.
Alright, I'll just use that in the future.*
>>
>>51554030
Oh, I do know it compiles. took me so long to respond because I was playing around with it.

What I mean is, for your situation, having different return types makes no difference in practice, since you're referring to object using pointer to base type.

>code
what
>>
>>51554029
I kinda knew that, but my knowledge of a better way of doing things was lacking, so I just did that to make my program run. Even I knew, that I should avoid doing that in the future.
>>
>>51553938
indeed finnish is mongolian language
fins are just chinese
>>
File: 1362865407497.jpg (127 KB, 895x595) Image search: [Google]
1362865407497.jpg
127 KB, 895x595
>>51554046
well basically now you just have to read up on how to actually structure your code or code on your own and frequently consult /g/. i see a few ways how your code is shit and should be restructured, mostly through wrapping parts of it in basic classes. also read up on "stl containers" and what they do for you. this is a good site for that http://en.cppreference.com/w/
for now start up with std::vector and std::unordered_map

then there are templates, function pointers etc.

also familiarise yourself with this https://en.wikibooks.org/wiki/C%2B%2B_Programming/Code/Design_Patterns later.
>>
>>51554080
No, during the development it's completely okay to copy paste as big as you want. But it is absolutely necessary to remove code duplication after you get it to work and make sure code does what you wanted. It makes it much much easier to read and maintain the program.
>>
>>51554046
>Use "\n" and std::flush instead
no, you can use endl, there's no reason to not use endl unless you expicitly want to not flush stream, it's just that you can write
endl<<"someshit", instead of writing cout<< two times.
>>
File: 1448439321350.png (154 KB, 253x395) Image search: [Google]
1448439321350.png
154 KB, 253x395
Any suggestions guise?

>>51554031
>>
>>51554070
code is what i use for my situation when i want to pack different types into single container and later access them
>>
>>51554116
Never thought about that. Thanks for the advice.
>>
>>51554070
>>51554030
Right. Well. As I have just found out, you can do what you want without any issues, using dynamic_cast.

struct A{
virtual void uudelleensuoritus(){ printf("A\n"); }
};
struct B :public A{
virtual void uudelleensuoritus(){ printf("B\n"); }

void do_B_things(){ printf("B things done!\n"); }
};
struct C :public A{
virtual void uudelleensuoritus(){ printf("C\n"); }

void do_C_things(){ printf("C things done!\n"); }
};

int main(int argc, char *argv[])
{

std::vector<A *> list;

list.push_back(new A());
list.push_back(new A());
list.push_back(new B());
list.push_back(new A());
list.push_back(new C());
list.push_back(new C());

for(unsigned int i=0;i<list.size();i++){
A *item=list[i];

item->uudelleensuoritus();

B *itemB=dynamic_cast<B *>(item);
if(itemB!=NULL) itemB->do_B_things();

C *itemC=dynamic_cast<C *>(item);
if(itemC!=NULL) itemC->do_C_things();
}

return 0;
}


Output:
A
A
B
B things done!
A
C
C things done!
C
C things done!
>>
File: hallway hooks.webm (1 MB, 626x714) Image search: [Google]
hallway hooks.webm
1 MB, 626x714
>>51553564
>>51553551
Ok I lied, I wasn't actually done with the maps. My autism wont let me rest.
Hallways are now valid targets for hooking more hallways onto, rooms have a chance to generate extra hallways with a few other neighbors, which makes the map more connected, rewrote method for doing hallways from scratch six times and counting.
I can now get naturally connected and looping maps withing having a ton of map spanning perfectly straight lines counterchanged against eachother.

It's 1am, there must be more to life than this.
>>
File: g_001.jpg (137 KB, 643x643) Image search: [Google]
g_001.jpg
137 KB, 643x643
>>51554154
>uudelleensuoritus
hey, weren't you starting c++ only yesterday?

also this isn't what i want, i want to make a method which will cast base class into derived without any input from the person that actually invokes it.
>>
>>51554208
That's not me (>>51553887), if that's what you meant, there's just some other mongolian roaming these plains
>>
Anyone have any recommendations of books to pickup for Android app development via java? Newbie here.
>>
>>51554234
/g/ - mon/g/olia
[spoiler]я и caм нa aлтae живy[/spoiler]
>>
>>51554158
Do you really need those long hallways?
>>
>>51554208
Just copied his variable name, because it's hilarious. Don't know what it means.

>also this isn't what i want, i want to make a method which will cast base class into derived without any input from the person that actually invokes it.
But that's impossible by design of the language. When you call a function, you either have to know exactly what it is, in case of non-virtual functions, or where in virtual table to look for it.

A *item=getItemFromSomewhere();

item->get_derived()->do_derived_things();


If the return type of get_derived() in base class is A *, then then compiler can only look for do_derived_things() in virtual table of A. And that does not have do_derived_things.

What you really want is the thing I posted. For your object that has a list of base object, create a function children<T>(), which will construct and return a list with children of type T (using dynamic_cast). Then the user can iterate over it and do whatever he wants with objects of particular type. It looks more or less good and is easy to both use and write.
>>
>>51554279
>>51554158
Those are some really long hallways you have there. It would be a shame if something happened to them.
>>
File: 1417765018965.jpg (57 KB, 564x518) Image search: [Google]
1417765018965.jpg
57 KB, 564x518
>>51554296
>tfw people find your native language to be hilarious.

Feels Fingoloid man.
>>
File: paivantsaja.jpg (36 KB, 273x720) Image search: [Google]
paivantsaja.jpg
36 KB, 273x720
>>51554355
>>
>>51554386
B-b-but muh mid-day/day's equator. That's the straight translation for "Päiväntasaaja".
>>
>>51554416
Hey, man, I'm not complaining.

Your language makes me smile.

Not many other languages can do that.
>>
>>51554279
>>51554318
the hallways are long to mimic the experience of being stuck in a long hallway. I'm expecting IGN to give me at least a 9.5 on this one.
>>
>>51554435
I have always wanted to know how my language sounds to foreign people. I guess it sounds strange. For example Tolkien used Finnish to be the base for the Elven language, so that makes me wonder what it actually sounds like to others.
>>
>>51554467
https://translate.google.com/#auto/fi/The%20Equator%20usually%20refers%20to%20the%20Earth%27s%20equator%3A%20an%20imaginary%20line%20on%20the%20Earth%27s%20surface%20equidistant%20from%20the%20North%20Pole%20and%20South%20Pole%2C%20dividing%20the%20Earth%20into%20the%20Northern%20Hemisphere%20and%20Southern%20Hemisphere.

Sounds sort of far eastern to me.
>>
Should I take online courses for programming in UDEMY ? they are on sale
>>
>>51554653
> online courses for programming
just programm
>>
>>51554735
But how will I get online certificate for taking online coures for UDEMY if I do not I take online courses for programming in UDEMY ?
>>
>>51554467
Finnish sounds like someone dropped you when you were a baby.
t. Viru Valge
>>
>>51553021
Is EVERYTHING just related to pushing responsibility away?

>Make this Java-App thread-safe.
>...Add synchronized Keywords everywhere.
>Load grows.
>Throw Hardware at it.
>Meanwhile Management reacts: What do you mean by "You don't understand Locking."?
>>
>>51554793
>Estonian saying, that Finnish sounds like that
>Estonian is basically a bootleg version Finnish.
You guys even have the same god damn national hymn

t. Viru Valge drinker from Finland
>>
>>51552886
>and now the mere sight of beaches and waves makes me ANGRY.
lmao
>>
>>51555005
>You guys even have the same god damn national hymn
ours is better 2bh
>>
File: 1417428522131.jpg (65 KB, 720x589) Image search: [Google]
1417428522131.jpg
65 KB, 720x589
>>51555111
>mfw
Also:
I guess we Finngoloids have shitposting in our genes or something, since I didn't even mean to, but I managed to derail this programming thread totally.
>>
>>51553887
IMO, for someone that just started (by your own, I suppose), it's OK
>>
Is it acceptable for an individual to ignore the possibility of truncation errors and their consequences when developing their own applications?
>>
>>51555197
Yeah, I started on my own. Been reading a lot of guides and analyzed other people's codes.

It's a start. Got some good tips here, so I can improve and head forward.
>>
>>51555198

It's acceptable for you to do anything when you're creating applications for your own use.
>>
>>51555198
As long as you don't use a trip, you're fine.
>>
>>51553887
You need descriptive variable names. Names that tell you what these variables are.

For instance if you have a list that store each of your clients you call the list "clientNames" or something similar. Code is meant to be produced in teams meaning others are meant to be able to understand your code if they see it.

Another example is, if you have a class for a person and you need to store the persons name, age, birthplace and job then you store it with variable names :

name
age
birthplace
job

These variables tell you what they store without having to look at documentation.
>>
>>51555272
Is it acceptable for an individual to declare himself anarcho-capitalist-libertarian-christian-statist while being racist and promoting "race" (whatever that means for ignorant murricans) mixing?
>>
Where would I go for help when I managed to completely break windows and turn my computer into a useless hunk of barren waste without even trying?
>>
C new fag here, question:
why \n is not necessary in printf when its followed by scanf?
example
printf("Enter first value: ");
scanf("%d", &val1);
printf("Enter the second value: ");
scanf("%d", &val2);


output will be, (on separate lines although \n was not used)
Enter the first value: 1
Enter the second value: 2
>>
>>51555294
jalkikysymys is more than descriptive you cunt. It has CHARACTER. I look at that and think, "Wow, what a nice looking variable name."
>>
>>51555320
https://www.gentoo.org/get-started/
>>
>>51555320
/g/
>>
>>51555320
Recycling plant
>>
>>51555364
Because you are the one who inputs the "\n" when scanf waits for input. The "\n" you input when you press Enter is shown on-screen because the standard input is your command prompt basically.
>>
So now that std.socketstream is deprecated in D, what do I use instead? Do I really have to go with the plain old C-style garbage way of dealing with data?
>>
javafag here
im replacing the RMI in my program with EJB. i have application clients, not web clients.

Question. in RMI, i manually implement observer pattern to notify all clients of changes in database. Does EJB have a feature to automatically notify clients or do i still have to observer pattern?
>>
>>51555428
Use C. It's more efficient than D by one letter.
>>
>>51554386
kek @ macedonian
>>
>>51555364
> When a stream is line buffered, characters are intended to be transmitted to or from the host environment as a block when a new-line character is encountered. Furthermore, characters are intended to be transmitted as a block to the host environment when a buffer is filled, when input is requested on an unbuffered stream, or when input is requested on a line buffered stream that requires the transmission of characters from the host environment.
7.19.3p3
IOW, reading from the console will flush output streams.
>>
>>51555316
>while being racist and promoting "race" (whatever that means for ignorant murricans) mixing?

What exactly does that mean?

>anarcho-capitalist-libertarian-christian-statist

Yee haw.
>>
>>51555422
>>51555455
Thanks a lot family <3
>>
>>51553727
>~600 pages or ~5k pages
>>
File: putin thumbs.gif (750 KB, 280x205) Image search: [Google]
putin thumbs.gif
750 KB, 280x205
>>51555446
>>
>>51555443
Really funny m8.
>>
File: I5nFwsl.jpg (97 KB, 690x769) Image search: [Google]
I5nFwsl.jpg
97 KB, 690x769
>>51555490
>>
>>51555493
Nigger do you think this is a game?
D for Dead
C for completely cute as fuck.
>>
>>51555294
I've been told this multiple times already in this thread. I do understand the point now.

They are Finnish words, tho. Now that I think about it, I bet that not even a Finnish programmer would understand the meaning of some of those, few of those are self-explanatory in Finnish.

But for the sake of logic, I'll just use English from here on.
>>
>>51555555
>>
>>51555535
More like C for Keks.
>>
>>51555576
That is a K, so you are dumb and wrong.
Typical Dong user.
>>
>>51555587
We both know that I meant Keks, it's just the 4chan filters.
>>
Should I make my own engine for C++ game
>>
>>51555673
If you enjoy wasting your time or have a unique approach with your game and no existing engine fits, go right ahead.
>>
File: c.png (63 KB, 449x498) Image search: [Google]
c.png
63 KB, 449x498
>>51555576

wew
>>
>>51555650
Yes, I get it, Keks. K.
>>
>>51555556
nearly checked
>>
keks
>>
>>51555705
yes, not quite though : (
>>
>>51555650
>mfw cyrillic got replaced too
Absolute haram.
>>
>>51555673
Look at some other engines first and figure out what's basic good design. Otherwise you'll just waste your time producing an abomination.

The better option is probably to just extend http://godotengine.org/
>>
>>51555693
<code>kek</code>
>>
>>51551801
You don't need to transpose; just apply the operations in the opposite order.
>>
c∪ck
>>
I actually want to make not a big game in C++, should I write my own library for it
library << engine, right
>>
>>51555718
at least you tried
well, rolled
>>
>>51555775
Just make the fucking game, don't care about what you should call what you make in the process.
>>
>>51555775
Library bit shift left engine?
As >>51555788 said, just make a game.
>>
>>51555775
just get SDL2 and start
>>
File: 1446195063311.gif (995 KB, 500x541) Image search: [Google]
1446195063311.gif
995 KB, 500x541
>mfw checking in a huge refactorization
no better feel than cutting away cancer code
>>
>>51555829
>new code is huge
>refactorisation

code monkeys like you will never become code monks like me
>>
>>51555845
and by huge i mean it covers many areas of the code
doesn't code monk enlightenment come with some basic read-between-the-lines skills?
>>
>>51555871
reading between the lines means ambiguity
>>
>>51555538
I'm not a native English speaker myself, however I program in English because it makes more sense. The terminology for programming is English so it just fits better to program in English.
>>
>>51555904
>English is the best programming language
>>
Working on something that involves dates and PHP.

Fuck dates and PHP
>>
File: 1443799265817.jpg (182 KB, 800x528) Image search: [Google]
1443799265817.jpg
182 KB, 800x528
>>51555911
>English
>good for anything
only thing it has going is that everyone knows it
>>
File: thank you jesus.jpg (62 KB, 504x470) Image search: [Google]
thank you jesus.jpg
62 KB, 504x470
>still trying to download MonoDevelop
>no mirrors in entire universe
>0.0 kbyte/s then Network Error

I want to get off Miguel de Icaza's wild ride.
>>
>>51555911
Documentation and naming conventions.
>>
>>51555944
Here's some C++ to make you feel better
>>
>>51555944
apt-get install monodevelop not working?
>>
>>51555957
>variable starting with an uppercase
TRIGGERED
>>
>>51555997

That works, but unfortunately I'm doing this from a [spoiler]WINDOWS[/spoiler] machine.
>>
Does anyone know a good weather api in java ?
>>
>>51556011
why use monodevelop? Why not Xamarin Studio?
Thread replies: 255
Thread images: 43

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.