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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 321
Thread images: 28

File: dpt_flat.png (102KB, 1000x1071px) Image search: [Google]
dpt_flat.png
102KB, 1000x1071px
Old Thread: >>56966686

What are you working on /g/?
>>
File: hime c.png (1MB, 1280x720px) Image search: [Google]
hime c.png
1MB, 1280x720px
First for 3-star programming!
>>
nth for D
>>
guess Ill try again before the for loop perf people start.

Alright guys, I need some serious c# help.. I'm half retarded obviously. The code is below. The real code hits a stored proc and returns a datatable with the results...

http://rextester.com/FPK90510

I need to now use that returned object in the calling function to use values later on.

I see that it is
System.Data.EnumerableRowCollection`1[<>f__AnonymousType0`2[System.Int32,System.String]]
but I fail on trying to cast it, enumerate over it, ect. How can I enumerate over this returned object so I may store the values in a list<dic<>>?
>>
Is there a way to iterate over a struct and run either strlen or uintlen depending on the type of each member?

I feel like there's a better way to write this.
static unsigned post_length(struct post *cm)
{
/* get approximate length of all data in struct */
unsigned len = 0;
len += strlen(cm->board_id);
len += uintlen(cm->parent_id);
len += uintlen(cm->id);
len += uintlen(cm->time);
len += uintlen(cm->options);
len += uintlen(cm->user_priv);
len += strlen(cm->del_pass);
len += strlen(cm->ip);
len += (!cm->name) ? 0 : strlen(cm->name);
len += (!cm->trip) ? 0 : strlen(cm->trip);
len += (!cm->subject) ? 0 : strlen(cm->subject);
len += strlen(cm->comment);
return len;
}
>>
5th for ++C
>>
>>56971303
https://www.youtube.com/watch?v=bLHL75H_VEM
>>
>>56971311
>probably. depends on the timeframe right? I have bipolar.
You could probably work an office job then I'd say.

If you're new to coding I think a Java or C# job might be easiest to get into..
>>
>>56971344
i tried this language and it's filled with pajeets

i hate /dpt/ memes
>>
>>56971383
#define len(x) _Generic(x, \
char *: x ? strlen(x) : 0, \
const char *: x ? strlen(x) : 0, \
int: uintlen(x), \
default: _Static_assert(false, "Reeeeeeeee") \
)

static unsigned post_length(struct post *cm)
{
unsigned len = 0;
len += len(cm->board_id);
len += len(cm->parent_id);
len += len(cm->id);
len += len(cm->time);
len += len(cm->options);
len += len(cm->user_priv);
len += len(cm->del_pass);
len += len(cm->ip);
len += len(cm->name);
len += len(cm->trip);
len += len(cm->subject);
len += len(cm->comment);
return len;
}
>>
>>56971442
Pajeets are everywhere m8.
You will even find them using Haskell.
>>
>>56971408
>You could probably work an office job then I'd say.
Well that's an awfully large assumption, bipolar can be a pretty severe condition.
What's a good approach to learning java?
>>
>>56971446
>_Generic

Why is C11 so perfect?
>>
>>56971446
>default: _Static_assert(false, "Reeeeeeeee")
That's pointless, because it'll fail to compile if it can't find a valid generic selection.
>>
>>56971456
Well if you can work to a deadline, then you can probably work in an office and call in sick or whatever when you can't handle it etc.

>What's a good approach to learning java?
Get a good book on it and work through it.
>>
>>56971494
Enjoy your inferior error messages.
>>
>>56971501
>Get a good book on it and work through it.
what's a good book on it?
>>
>>56971456
muh dick is pretty severe
>>
>>56971514
Dunno.

This one is probably good for a newbie like yourself:
https://www.amazon.com/Head-First-Java-Kathy-Sierra/dp/0596009208
>>
>>56971536
ty
>>
>>56971503
>error: ‘_Generic’ selector of type ‘float’ is not compatible with any association
>test.c:17:2: note: in expansion of macro ‘len’
I think that already a pretty good error message.
>>
>>56971614
Compare:
>error: static assertion failed: "Reeeeeeee"
>>
>>56971383
keep an array with the sizeof() and offsetof() values of every array member.
Cast the struct as a char * array and then loop through something like
if (sizes[i] == sizeof(char *))
{
char *a = arr + offsets[i];
len += (!a) ? 0 : strlen(a);
>>
#include "global.h"

struct entry keyword[] = {
"div", DIV,
"mod", MOD,
0, 0
};

init() /* loads keywords into symtable */
{
struct entry *p;
for (p = keywords; p->token; p++)
insert(p->lexptr, p->token);
}

I don't see any reason why this should be done at runtime. How do i do this at compile time?
>>
File: ZNrSwMX.jpg (420KB, 2915x2358px) Image search: [Google]
ZNrSwMX.jpg
420KB, 2915x2358px
In C#, if I have several threads that may or may not write to a file at the same time and that use DIFFERENT StreamWriters, what would be a good way of resolving conflicts, assuming that they arise fairly often?

Just while(true) ing it and then breaking out when it actually manages to write to the file?
Order of the text written to the file does not matter as long as it doesn't seive it (I.E. Apple and Bananna being written at the same time should not result in ABpapnale
>>
I hate programming but I majored in Comp Sci and graduated. What do I do to make myself actually enjoy coding so that I do it when I'm bored instead of spending all day playing around with my guitars
>>
>>56971664

What, exactly, are you trying to accomplish? What is your program doing?
>>
>>56971664
>I have several threads that may or may not write to a file at the same time and that use DIFFERENT StreamWriters
Why not just write to multiple different files and then combine them at the end?
>>
>>56971664
What kind of writing is it? Just appending stuff to the end of a file?
>>
>>56971651
Your stupid reddit meme doesn't tell the user anything.
>>
I have to write a paper for my software engineering class. What are some topics you find interesting? Anything related to enterprise software development, I don't really have a burning desire to write about anything yet
>>
>>56971698
I'm porting over my data aggregator from Java, so it's asynchronously reading a bunch of pages and then saving them to a digest if the text matches certain parameters
Since it scans a ton of pages at once and any given page has a chance of giving a match, you can get two write requests at the same time

>>56971705
Unwanted overhead + I want the contents to be usable even if the scan is canceled/hits an exception/X Y Z thing goes wrong

>>56971737
Cryptography/security
There's a lot to learn and it's a lot of fun
>>
>>56971749

How'd you handle this issue in Java?
>>
File: 1475784357595.png (29KB, 740x380px) Image search: [Google]
1475784357595.png
29KB, 740x380px
Posting this again. I am looking for tutorials on using selenium with python for automated mobile web testing.

Gone through a few but I would like more. A lot are using java instead of python.
>>
>>56971758
I didn't have to. I forgot that I'd have to handle it so I didn't, and it produced readable output because it apparently waited for the file to be ready before it wrote to it.
>>
>>56971000
If you're in a situation where a do-while works, you should probably be using that.
>>
>>56971749
One thing you could do is add all the new strings you want to write to each file to a concurrent queue for each file. Then have one thread whose job it is to flush the queue by writing everything in it to the file.

Everytime you add a string to the queue from any other thread you should also invoke the "clearQueue()" method on that file writing thread.
>>
>>56971664
>DIFFERENT StreamWriters
Don't.
Maintain only one StreamWriter to your file, and provide a mutex protected interface to that StreamWriter.
>>
>>56971778

Why not share a Streamwriter between the threads? Look at ReaderWriterLock.
>>
>>56971664
I'm not sure what you're trying to accomplish, the most basic thing to do would be to use some sort of exclusive lock in order to guarantee that only one thread writes at a time. The other threads that want to write would block until the lock is released and then another thread gets to write. This approach may be inefficient if the writes are large and collisions are frequent/likely, because that could mean threads spend a lot of time waiting around for the lock.

You could also make a single thread that writes whatever it gets through some sort of multithreading-capable queue object. Instead of writing to disk, your threads push the data onto the (in-memory) queue. The single writer thread waits for something to be available on the queue and then writes that to disk. This would almost certainly have better performance because your working threads don't have to wait for the actual write operation to complete, so while the writer thread writes from the queue, they can do their own thing.

These are just general ideas that should work in any language, I don't remember C# specifics.
>>
>>56971664
Yeah you can't do that. You need to use one writer.
>>
>>56971869
>>56971843
damn
thanks anons
>>
>>56971843
>>56971878
Surely there's some kind of concurrent StreamWriter or some shit on NuGet..
>>
>>56971660
h-here i go!
/* for struct iteration */ 
enum post_fields { TEXT = 0, NUMERIC = 1 };
enum post_fields types[] = {
0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
};

static unsigned post_length2(struct post *cm)
{
/* iterate over struct to get length of data */
unsigned char *mem = (unsigned char *) cm;
unsigned len = 0;
unsigned offset = 0;
unsigned i;
for (i = 0; i < static_length(types); i++)
{
if (types[i] == TEXT)
{
char *str = &mem[offset];
len += (!str) ? 0 : strlen(str);
offset += sizeof(char *);
}
else /* NUMERIC */
{
long *num = &mem[offset];
len += uintlen(str);
offset += sizeof(long);
}
}
return len;
}
>>
>>56971928
Found the javascript dev.
>>
>>56971963
Well, I do know JavaScript among many other langugaes anon.
>>
>>56971660
>>56971939
This seems like a pointlessly unportable way of doing that, and violates the strict aliasing rule.
>>
>>56971928
Do you also need a NuGet package to add two numbers together?
>>
>>56971928
Maybe, but fuck if I know. I only ever really use C# as a hobby language when I want to make some Windows GUI application.
>>
>>56972010
No anon, that's built into the language you dumb fuck.
>>
>>56971928

There's already ReaderWriterLock.
>>
>>56972053
only lets you write from a single thread it seems.
>>
New assignment in microprocessors class. Have to write a calculator that respects order of operations over +, -, *, /. Has to be infix. Has to support variable definition and substitution. Has to be written in MIPS assembly.

Writing all the workhorse functions now: parseint, strcmp, strcpy, isspace, isdigit, etc.

After this we get to implement a pipelined single execution unit CPU in Verilog. At least we don't have to do a IEEE754-compliant floating point unit like the grad students do. Hopefully we get more than two weeks for that.

Should be interesting. But fuck me.
>>
>>56972089

It's designed to lock a writer for use with multiple threads.
>>
>>56972137
yeah, but only for reading from multiple threads. Not writing. I just read the documentation.
>>
I "learned" verilog when we did The same CPU. Didn't actually learn it until I did a real cpu.
>>
>>56971928
Why would I do that, even if there was one?
If it's not the right way to do it, I'll do it a different way. I only use nuGet for stuff that's hard and that I don't want to do because it's reinventing the wheel, like parsers.

>>56971810
Does this look about right? According to the documentation, the using block causes a lock on the fileStream. If I write multiple files, they should wait for the lock to stop, correct?

private static FileStream fileStream;
public static void Save(MemoryStream stream, FileInfo fileInfo) {
FileMode fileMode;
if (data.gallery)
fileMode = FileMode.CreateNew;
else
fileMode = FileMode.Append;

using (fileStream = new FileStream(fileInfo.Directory.ToString(), fileMode)) {
byte[] bytes = stream.ToArray();
fileStream.Write(bytes, 0, bytes.Length);
}
}
>>
>>56971454
shieet
>>
>>56972235
>If it's not the right way to do it, I'll do it a different way.
Don't know how good a way there is to do it. You could just lock that streamWriter for each file I guess, but that seems dirty to me. Feels wrong to freeze threads awhile waiting for another thread to finish writing when you could just be buffering stuff you want to write without blocking anything.
>>
>had telephone interview for C++ position
>get output ordering of cout some string with inheritance of a class b with a virtual base class a vs regular base class a wrong
>get atoi implementation wrong if you enter in partial trash like 12abc, where number is 120 instead of 12
>we'll follow up with you with a project-sized task for you to complete.

I feel like I fucked up and they won't call me for an on-site interview after I complete the project-sized task ;_;
>>
>>56972179

You can write from multiple threads, but can only write from one at a time.
>>
>>56972235
>the using block causes a lock on the fileStream.
Assuming this is correct then yes that should work correctly.

I think ideally you would have the data collect into a buffer or something so that none of the threads have to wait for a different thread to finish writing. So I guess if you run into performance issues you should look into that. But that should only help if the bottleneck is writing enough data fast enough to the disk.
>>
>>56972225
>Real CPU
?
Like superscalar OoO w/ branch prediction and the whole mess?
>>
>>56972235
>multiple files
*if I write to the same file at the same time

>>56972271
Since I have to use a single writer now i'm just going to make a file queue and make it write so quickly/concurrently that the disk's bottlenecking will be the only thing preventing me from saving files as fast as I want

>>56972315
Literally what I was writing in my above reply lmao
thanks anon
>>
>>56972317
Lol no. It has a true pipeline, assume false branch prediction, multicore, full important instruction set. It's a real mess I want to redo, but can't justify the time.
>>
>>56972137
Austin, I'm stuck on some JNI stuff.
I'm trying to work through it so I don't spam the board, but I might need some help in a few days
Just letting you know
>>
>>56972360
You have that up on guihub? I'd love to look at it.
>>
>>56972375

You should just drop Java and pick up C#, because then you don't have to deal with JNI at all. You can do everything from C# and it jest werks.
>>
File: readerwriterlock.png (9KB, 185x740px) Image search: [Google]
readerwriterlock.png
9KB, 185x740px
To be clear, this is the output you'll get from using a ReaderWriterLock. Only used one StreamWriter, and launched threads for each fizzer (which waited a random amount of time, just to introduce some out of order numbers).
>>
File: nolock.png (12KB, 929x411px) Image search: [Google]
nolock.png
12KB, 929x411px
And here's the output when I just call sw.Write without actually getting the lock.
>>
>>56972381
It's one of the 20 that come up from "RISC cpu language:verilog".
>>
File: LpLeCC4.png (54KB, 140x152px) Image search: [Google]
LpLeCC4.png
54KB, 140x152px
Can anyone recommend a cozy Python GUI library? TkInter looks a bit wonky to me.
>>
>>56972524
Write one.
>>
>>56972524
Don't use python for gui. It's good for a lot of things, gui is not one of those things.
>>
>>56972839
Could you recommend another language, anon? I rarely write for GUI to be honest
>>
>>56972389
I plan on learning C# soon, as there are dozens of things that I plan to create with it, but I need to finish this game I'm making for Android, which requires Java.

I can't start a new language before I have finished my first real project.
>>
>>56972860
C# or Java
>>
What's a good Java book for experienced programmers? Nothing more than 300 pages please.
>>
>>56972860
C++ is good but really hard. C is easier but idk how it is for gui. Java is prolly gunna be your best bet. I would suggest learning C++ and qt which would give you the best results though, gunna be a lot of work though.
>>
>>56972880
>I can't start a new language before I have finished my first real project.

Of course you can. I think everybody here has 100 unfinished projects.
>>
>>56973042

At least 100 unfinished projects...
>>
>>56972977
Java in a Nutshell, 6th Edition.
>>
>>56973067

Don't remind me. :(
>>
>>56972978
Qt made me cry.
>>
Racket noob here: how can I define a member function for each attribute in my class?
The following doesn't work....
(define-syntax record
(syntax-rules ()
[(record <Class> (<attr> ...))
(begin
(define (<Class> <attr> ...)
(instance <Class>
(<attr> ...)))
(map (λ(attr)(define (attr msg) msg)) (list <attr> ...))
)
]))
>>
>>56973042
Well, I could, but I don't want to.
There's only about 5 lines of java, and 4 lines of C++ that have to be written, as well as the C++ library being compiled. I'm currently in contact with the library author, asking where the source code is.

Once those 9 lines are done, I can continue and have my game done within a month or two hopefully.
>>
>>56972491
Thanks man. Any tips on turning Verilog into a sane development language?
>>
How does one increase their skill at developing "clever" solutions to programming problems?

Lately I've been completing exercism, hackerrank, etc... problems. It seems as if my solutions are always naive and simple. They work, and they are definitely readable, but they just lack that special ingenuity.
>>
File: 1475691080870.png (123KB, 401x361px) Image search: [Google]
1475691080870.png
123KB, 401x361px
>>56973190
>I can continue and have my game done within a month or two hopefully.

Reality isn't so forgiving.
>>
>>56973213
ingenuity is extremely overrated
>>
>>56973213
Clever tricks aren't good for readability. You are doing god's work.

And I don't think it's something you learn, it's something you have, and it's something you can develop if you already have it, but you don't...
>>
File: last.png (37KB, 1919x405px) Image search: [Google]
last.png
37KB, 1919x405px
Still working on my terminal, done the formatting part for control codes, now just getting awfully bored writing tests for the whole parsing/formatting bullshit. It already found few bugs so I'm okay with it.

Screenshot from yesterday, rendering a colored mixed single/double width character string PS1 from bash.
>>
>>56973099

The one thing I'm wondering is whether I will continue making unfinished projects when I've finally gotten a job...
>>
>>56973074
Why are authors of Java books always so defensive?
>>
>>56973253

I plan to continue creating unfinished personal projects when I have a job.
>>
>>56973213
Not that guy, but you need to have a clear understanding of the cost of your solution. How much space does it take up? What is the runtime complexity? If the naive solution happens to be the most efficient, then whatever. Usually, this is not the case. Decreasing your function by an order n can mean the difference between getting a good job or not. Anyone with a brain can usually think of a naive solutoin, the question is how do you improve on the naive solution. Thats where the "ingenuity" comes in, i.e. some sort of dynamic programming approach (usually)
>>
>>56973267
Mark of a guilty conscience.
>>
Does anyone have any experiences with Google App Engine, their memcache cloud database and their nosql cloud database?
I'm writing the backend for an app and I have been tinkering with go for a while so I thought it could be something decent to try and get some experience in with.
>>
>>56973232
>>56973245
Well...I still feel bad man.

Here's an example -

my solution to a "hamming distance" problem.
public class Hamming {

public static int compute(String strandA, String strandB) {
if( strandA.length() != strandB.length() ) throw new IllegalArgumentException("DNA Strands Must Be " +
"of Equivalent Length!");
int hammingDistance = 0;
for( int i = 0; i < strandA.length(); i++ ) {
if( strandA.charAt(i) != strandB.charAt(i) )
hammingDistance++;
}
return hammingDistance;
}
}


some hot-shot's solution to a hamming distance problem -

import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.function.*;
public class Hamming {
public static int compute(String l, String r) {
if (l.length() != r.length()) {
throw new IllegalArgumentException();
}

Function<Integer, Integer> quantify = i -> (l.charAt(i) != r.charAt(i)) ? 1 : 0;
Function<Integer, Function<Integer, Integer>> plus = x -> y -> x + y;
Function<Integer, Function<Integer, Integer>> composed = plus.compose(quantify);

Function<BinaryOperator<Integer>, BinaryOperator<Integer>> flip = f -> (x, y) -> f.apply(y, x);
Function<Function<Integer, Function<Integer, Integer>>, BinaryOperator<Integer>> uncurry = f -> (x, y) -> f.apply(x).apply(y);

BinaryOperator<Integer> step = flip.apply(uncurry.apply(composed));

Stream<Integer> indexes = IntStream.range(0, l.length()).mapToObj(i->i);
return indexes.reduce(0, step);
}
}
>>
>>56973213
What people call "clever" programming is the culmination of your experience as a programmer.
The more dumb tricks and idioms you're exposed to, the more often you'll incorporate them into your software.

Just write more, and read other people's shitty software for tricks to steal.
>>
>>56973340
Now I remember why I quit Java for C.
>>
>>56971662
You could use gperf, it can generate your lookup function.
>>
>>56973074
That book seems to be rather low quality. The author does not seem to know the difference between Unicode and UTF-8 and seems to think that all unicode values fit in 16 bit.
>>
>>56973385
... and avoid the need to have your own dict and populating it at runtime.

Thought I should clarify that a bit.
>>
>>56972524
>>56972860
Tkinter needs to be used alongside a guide until you "get" it. It's really bad/dense for how "simple" it is. If you still want to give Tkinter a shot, use this. It's the best guide I've seen and even then it's not great.

http://www.tkdocs.com/tutorial/

Considering writing my own when I finish this project.

You could use C# which has XAML (probably the best GUI designer I've ever used) but that can get messy quickly because lol microsoft. C++/qt seems to be one of the more common GUI solutions as >>56972978 mentioned.
>>
>>56973340

This hot shot's solution is practically unreadable.
>>
>>56973201
Pen and paper. You shouldn't start writing until you know exactly what you're going to do, because it'll turn into a huge mess if your don't. Also modules should be fairly simple, in my opinion. Lastly, if you're going to synthesize it, learn what is and isn't synthesisable BEFORE you start the project.
>>
>>56973477
Who doesn't want to read the type
Function<Function<Integer, Function<Integer, Integer>>, BinaryOperator<Integer>>
?
>>
>>56973477
>>56973505
yeap but just the fact that he was able to come up with that functional magic and all his test cases still passed, was a challenge of it's own.
>>
>>56973521

He was code bowling. Don't give into it.
>>
>>56971303
If I'm applying for a C# position, it's a bad idea to put in the CV that I know to program in C, Sepples, and Ruby? (I've programmed in those langs before, but haven't used them in like years, so I'm a bit rusty).
>>
>>56973521
True, but it's much more readable in Haskell or some other FP lanuage, and expresses the same thing. The hard part here is using the Java-specific features necessary. I haven't really put in the effort to read it, but it still seems unnecessarily complicated, speaking within the scope of using FP operations.
>>
>>56973274

Excellent! So I won't be alone in this regard.
>>
>>56973253
>>56973274
I don't feel as bad knowing there's more of you out there.

Is anyone else interviewing with big four companies? How is it going?
>>
>>56973449
Thanks. But i still need to be able to add arbitrary entries to the dict at runtime, after initial population, so i don't think that will work.
>>
>>56973215
As long as I know how to edit this native code, I shouldn't run into any other week long set backs.

There's a .jar file containing two .dll files, and a few .so's, and I have no idea where the .cpp file that I've edited has to go.
>>
>>56973340
>Function<Function<Integer, Function<Integer, Integer>>, BinaryOperator<Integer>>

What the fuck is this?
>>
>>56973544
explain?
>>
File: 3.png (39KB, 1000x1071px) Image search: [Google]
3.png
39KB, 1000x1071px
>>56971303
your shitty image is now optimized!
>>
>>56973692
what the fuck?
>>
>>56973477
The problem is Java's braindead type syntax, clumsy function application syntax, and the fact that you have to write the types at all. Here's the same code without the types:

flip = f -> (x, y) -> f.apply(y, x);
uncurry = f -> (x, y) -> f.apply(x).apply(y);

quantify = i -> (l.charAt(i) != r.charAt(i)) ? 1 : 0;
plus = x -> y -> x + y;
composed = plus.compose(quantify);
step = flip.apply(uncurry.apply(composed));
indexes = IntStream.range(0, l.length()).mapToObj(i->i);
return indexes.reduce(0, step);


And in Haskell:

-- flip and uncurry are already defined standard
compute l r =
let quantify = \i -> if l !! i /= r !! i then 1 else 0
plus = \x y -> x + y
composed = plus . quantify
step = composed -- foldr's argument function already has the right argument order
indexes = [0..length l - 1]
in foldr step 0 indexes


Or, in actually idiomatic Haskell:

compute l r = sum (map quantify [0..length l - 1])
where quantify i = if l !! i /= r !! i then 1 else 0


GHC's automatic deforestation (made possible by lazy evaluation) means you don't need to explicitly fuse the quantification and summation in a single reduce, you just say what you mean.
>>
>>56973769
>GHC's automatic deforestation (made possible by lazy evaluation) means you don't need to explicitly fuse the quantification and summation in a single reduce, you just say what you mean.
what the fuck are you talking about, bro?

like, what the fuck is this nerd shit
>>
>>56973692
It's a function which takes in a function, which takes in an integer and outputs a function on the integers, which returns a binary operator on the integers.

What are you, stupid?
>>
>>56973787
he's saying that the haskell standard library has rewrite rules that can detect that you're doing unfold -> map -> fold and completely alleviate the intermediate data structure
>>
>>56973787
sum . map quantify

is much easier to read than fusing the two reductions explicitly:
foldr (\x xs -> quantify x + xs)

GHC compiles the first to the second for you.
>>
>>56973819
pretty sure it fuses the enumFromTo ([0..length l - 1]) as well
>>
>work at a small business for a bit, doing embedded dev
>everything is going great
>boss hires some batshit crazy SJW girl to do web shit
>a couple months later he starts talking about how we need a more diverse engineering team

I thought embedded development was safe from all of this PC and forced diversity bullshit.
Since I'm a white dude, how long until I get laid off?
>>
File: carlos.png (272KB, 560x560px) Image search: [Google]
carlos.png
272KB, 560x560px
>>56973852
>batshit crazy SJW girl
>he
>>
>>56973805
That's really cool anon, thanks.
>>
>>56973830
So yeah, the generated machine code is just a loop on integers.

Well, there is the issue that using the (!!) operator on strings in quantify is definitely worse than String.charAt(int). I don't know if GHC is able to improve that, I wouldn't expect it to.
>>
>>56973859
"he" is the boss obviously.
>>
>>56973852
How essential are you to their team?
>>
>>56973876
So on second though, the actually idiomatic code would be this:

compute l r = sum (zipWith score l r)
where score lc rc = if lc /= rc then 1 else 0
>>
>>56973903
fromEnum (lc /= rc)
>>
>>56973213
>The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.
Edsger W. Dijkstra
>>
>>56973937
A "clever trick" and discovering algorithm with a fundamentally different time complexity are separate things, imo.
>>
>>56973899
I'm kind of important, I guess.
I do most of the software design and programming, and I manage the other software developers.
I'm really hands-off in my management though, so it's not like I do much managing.
>>
>>56973966
wat? That is a quote by Dijkstra.
>>
>>56973720

Code bowling is the opposite of code golf. In both, the resultant code is unreadable, but in code bowling, a higher score is better.
>>
>object code
>.o (object) files

holy shit C is actually OOP
>>
>>56974144
Idiot.
>>
if(argc > 1){
offset = atoi(argv[1]);
}

Why is this C code giving me a parse error? offset is an int defined to be 0 initially, and the main function has params int argc and char *argv[]
>>
>>56973484
Pen and paper is the only way. Or nice big whiteboard in my case.
>learn what is and isn't synthesisable BEFORE you start the project
Does this mean more than "learn the language because compile times are a bitch"? I've done two classes in Verilog. It seems like every lab I learned something new that made it less of a hassle to develop in. Probably the most useful ones were parameters and `default nettype none.

How did you handle large complicated state machines like what I'm sure the decoder will end up being?
>>
>>56974144
>lvalues are objects in C
OMG you're fucking right.
>>
>>56974164

argv works like regular arrays with 0 indices...

So you want argv[0], most likely.
>>
Can someone who knows Haskell comment on my sieve of Eratosthenes? With my level of experience I'm happy it works at all, but of course I want to make it better. I mostly wrote it so I could get experience working with IOArrays, but I feel like in a practical program it would be a lot simpler to use a map, even if it means where I use writeArray and readArray would go from O(1) to O(log n).
limit = floor . sqrt . fromIntegral

sievePrime :: IOArray Int Bool -> Int -> IO (IOArray Int Bool)
sievePrime arr p = do
(_,size) <- getBounds arr
mapM_ (\i -> writeArray arr i False) [p*2,p*3..size]
return arr

sieveIfPrime :: IOArray Int Bool -> Int -> IO (IOArray Int Bool)
sieveIfPrime arr i = do
isPrime <- readArray arr i
if isPrime then sievePrime arr i else return arr

sieve :: Int -> IO (IOArray Int Bool)
sieve size = do
arr <- newArray (2,size) True
mapM_ (sieveIfPrime arr) [2..limit size]
return arr

primesCons :: IOArray Int Bool -> Int -> IO [Int] -> IO [Int]
primesCons arr p t = do
isPrime <- readArray arr p
lst <- t
return (if isPrime then p:lst else lst)

primesUnder :: Int -> IO [Int]
primesUnder i = sieve i >>= \arr -> foldr (primesCons arr) (return []) [2..i]
>>
>>56974195
argv[0] is always program name
>>56974164
what if you change main parameter from char *argv[] to char **argv?
>>
File: 1386142069975.jpg (84KB, 674x505px) Image search: [Google]
1386142069975.jpg
84KB, 674x505px
>>56973739
Thank you Mr. PNG Optimizer man! Our CPU cycles are too precious to waste optimizing PNGs, and our disk space too value not to! Have an internet.
>>
>>56974164
What command line arguments do you provide?
>>
>>56974201
kek :: [Integer] -> Integer -> [Integer]
kek seq p = filter (\x -> x `mod` p /= 0) seq

sieve :: [Integer]
sieve = unfoldr (\(p:rest) -> Just (p, kek rest p)) [2..]
>>
>>56974195
Even if that was true, the fact that it's a parse error and not an error at run time makes the indices irrelevant.

>>56974210
Aren't those literally the same things?

>>56974218
Just a number, hence atoi and stored into int offset
>>
>>56974164
is that code in main or in other function call?
>>56974243
yeah it works the same
>>
>>56974201
updateArray f arr i = ...
-- read arr at i
-- apply f to result
-- write it to arr at i
>>
>>56974241
I've seen that and it's pretty cute but not a sieve of Eratosthenes.
>>
>>56974260
Thanks, I'll try to see where I can use that!
>>
>>56974258
It's in main.
And unless my C compiler is 100% stupid, the change from [] to ** should make no difference. Will try it right now though.
>>
>>56974286
Post full. You are probably just missing a semicolon or bracket somewhere.
>>
>2016
>not letting the kernel handle your file synchronization

int eventfd_sharing_master() {
int fd = open("/tmp/foo", O_CREAT | O_RDWR);
int evfd = eventfd(0, 0);
eventfd_write(evfd, (uint64_t) fd);
fd = -1; // invalidate fd from open()
bool master = false;
if (fork() == 0)
if (fork() == 0)
if (fork() == 0)
if (fork() == 0)
master = true;
uint64_t v;
for (int i = 0; i < 10; ++i) {
usleep(50000);
eventfd_read(evfd, &v);
char buf[64];
int len = snprintf(buf, 64, "pid %i: %i\n", getpid(), i);
write((int) v, &buf, (size_t) len);
eventfd_write(evfd, v);
}
close(evfd);
if (master)
close((int) v);
return 0;
}
>>
>>56974201
>primesCons :: IOArray Int Bool -> Int -> IO [Int] -> IO [Int]
Can this function be written with the type IOArray Int Bool -> Int -> [Int] -> [Int]? The answer is no because we need to read from the IOArray, right?
>>
>>56974243

What's the range of offset? atoi might not be appropriate if it is out of range.

And you could try making argv a VLA by using argv[argc + 1].
>>
>>56974357
>the answer is no
yes
also because you need to access an IO [Int]
>>
>>56974168
There's valid verilog and synthesisable verilog. One thing I fucked up was combining a negedge and a posedge in the watch list for an always block.

For the states of each stage, you can do case statements to determine the flags you need for each module. These will get propagated with the data through the state registers. You can get pretty clever with this as far as optimizations go and picking your opcodes well.
>>
Just a program that calculates time complexity.
try
{
switch(argc)
{
case 1:
cout << "Enter input file. ";
cin >> input;
cout << "Enter output file. ";
cin >> output;
break;

case 2:
strcpy(input, argv[1]);
cout << "Enter output file. ";
cin >> output;
break;

case 3:
strcpy(input, argv[1]);
strcpy(output, argv[2]);
break;

default:
throw tooManyArguments(argc);
break;
}
}
catch (...)
{
cout << endl << "An error occured." << endl;
exit(EXIT_FAILURE);
}

ifstream i(input);
ofstream o(output);

if(!i)
throw exceptionOne(input);

if(!o)
throw exceptionOne(output);
if(i.is_open())
{
while(getline(i, hold))
{
i >> hold;
inputInfo[c] = hold;
c++;
}
i.close();
}
for(int y = 0; y < 10; y++)
{
convert[y] = atoi(inputInfo[y].c_str());
}
>>
>>56974483
>only 25% is actual useful code
>because of shitty language it takes up like 25 lines
>>
I am reading a C# book but my gay ass keeps getting distracted by games and texting, what should I do to focus more on learning ?? I am in desperate need of help.
>inb4 kys
>>
>>56974513
just remember
don't be on fire
>>
>>56974513
Uninstall gaymes and put a password on your phone to make it more of an effort to use.
>>
>>56974503
Did I write shitty code? lol
>>
>>56974513
Install Linux, learn a better language or use Mono, put phone away. Or just pick up a project you actually care about.
>>
>>56974513
2hu music & pomodoros
>>
>>56974722
not him but how do i into 2hu
>>
>>56974735
Youtube, search "touhou playlist"

Gelbooru, search reisen_udongein_inaba paizuri
>>
File: 1472542525496.png (34KB, 400x250px) Image search: [Google]
1472542525496.png
34KB, 400x250px
do I need to free() all nodes in a list/queue/stack or just the first one is enough?
>>
File: 2430213e8e.jpg (418KB, 1338x705px) Image search: [Google]
2430213e8e.jpg
418KB, 1338x705px
>>56974735
Play the games, search for the english patched ones, they're pretty easy and kinda boring, but the OST are fucking glorious. Then start looking into /jp/ memes and touhou doujinshis.
>>
>>56974513
books on programming languages are usually pretty boring. are you coding while you read?
i don't learn much from videos but maybe you could
>>
>>56974782
all of them
>>
File: version numbers.png (13KB, 404x438px) Image search: [Google]
version numbers.png
13KB, 404x438px
What's going on here?
>>
>>56974782
If you think about this some more you should be able to figure out the answer yourself
>>
>>56974782
Like anon said, all of them, but first the members of the structs, then the nodes, gotta watch out for lost references.
>>
>>56974841
There's some faggotry among the fag community about whether fag 2.7 or fag 3.4 is better
>>
>>56974866
Are there also faggots arguing about the differences between fag 3.4 and fag 3.5?
>>
File: 1459887454920.webm (428KB, 469x720px) Image search: [Google]
1459887454920.webm
428KB, 469x720px
>>56974824
>>56974842
>>56974852

Yeah that's why I'm asking
I mean if I free() the first one I'm losing the reference, "destroying" the list/stack/queue so I don't need to free() the other nodes, right? [spoiler]R-right?[/spoiler]
>>
>>56974887
Save the next node on a temp variable, destroy current node's member, destroy current node. Repeat until null node.
>>
>Have to write a bunch of trivial classes with getters/setters for every variable, and constructor to set every variable.
>Have to write test cases for each concrete class
>The concrete classes don't add much anyway so there's a lot of duplication in the test cases
>All in Java
Please someone kill me.
>>
>>56974954
welcome to OOP
>>
>>56974967
This isn't OOP, this is POOP.
Sane OOP is different to Java/C# OOP (POOP).
>>
>>56974887
use valgrind and see for yourself
>>
>>56974980
>sane OOP is different to OOP written by OOP experts in OOP languages
the difference is that "sane OOP" doesn't actually exist
>>
>>56974985
If he doesn't know the answer to that, do you really think he's going to have a clue how to use valgrind?
>>
>>56974989
Then how am I using it?

Protip: sane OOP is basically just procedural programming with classes added in, or in other words, C with classes.
And it is the only sane and sensible way to use classes.
>>
File: 1459926416792.jpg (25KB, 263x263px) Image search: [Google]
1459926416792.jpg
25KB, 263x263px
>>56975008
>>
>>56975020
POOP in the loo, pajeet.
>>
>>56974999
he can run it with one command, and then see OVER 9000 BYTES DEFINITELY LOST
it's useful
>>
File: 1451350466320.webm (584KB, 1280x720px) Image search: [Google]
1451350466320.webm
584KB, 1280x720px
>>56974915
>>56974985

I thought that by free()ing the first node the rest of the list/stack/queue would free() themselves.

C is stupid why would I want scattered memory blocks without a way to access them? Just be a bro and free() the rest for me you dumb fuck.
>>
>in interview
>implement the malloc function call
>me
void *my_malloc(size_t size)
{
return malloc(size);
}
>>
why would i ever cast a value
>>
>>56975038
C is not your mom.
>>
File: 1475332797992.jpg (171KB, 1280x1024px) Image search: [Google]
1475332797992.jpg
171KB, 1280x1024px
>>56975008
>sane OOP is just method call syntax!
>>
>>56975046
you're hired
i know a guy who had an interview and they were testing him in python. the task was to eliminate duplicates in an array and the desired answer was list(set(a))
>>
>>56975058
Classes implies inheritance and shit I think.

I dunno, I think OOP is silly. It's a cute idea though.
>>
>>56975091
>cute idea though.
>>
>don't use inheritance
>inheritance is OOP
> ???
>>
>>56974820
I am coding while reading the book, it is like a video in a way because it makes me write the code that comes with a cd with prewritten code for me to edit out and what not. It is decent so far.
>>
>>56975058
No, sane OOP is forgetting about the meme known as encapsulation, having private members is absolutely fucking useless.
>hur dur would you like anyone to just come and modify your members?
I fucking hate this, THIS IS NOT HOW IT FUCKING WORKS, do not apply this stupid fucking thinking to programming.

Don't shove absolutely everything into a class, not everything needs to be in a fucking class. A lot of the time just a bunch of namespaced functions is better.
Don't make trivial classes with all the getters/setters and constructors that just store a bunch of variables with no functionality, make it a simple fucking struct for fucks sake, it's okay to have some validation and utility methods though.

Inheritence, composition, and polymorphism are useful and powerful features, but make sure you use them sensibly and be mindful of the is-a and has-a rule.
Don't go overboard with polymorphism, limit it to interfaces and/or abstract classes.

Don't use exceptions.


There, OOP without the poo.
>>
>>56975212
>sane OOP is forgetting about the meme known as encapsulation
OOP is all about encapsulation. What you're doing is not OOP, it's procedural programming.
>Inheritence
I think even a lot of OOPfags have gone off of inheritance.
>>
>>56975212
>inheritance
>polymorphism (OOP polymorphism)
very restricted form of much simpler and neater technique
just use higher order functions

>composition
Not remotely OOP.
>>
Anyone have the article from a woman who described herself as a "UX Engineer" who went to a programming interview, couldn't answer anything, and threw a fit?

It's a few months old I think and I'm pretty sure she took it down but someone had stored an archive of it.
>>
>>56975236
>I think even a lot of OOPfags have gone off of inheritance.
And that's how you spot retards.
>>
>>56975247
To be fair, what does UI design have to do with programming?
>>
>>56975212
It sounds like you'd like Python. I guess you wouldn't like the ask forgiveness not permission thing because in Python it's interpreted as "use error catching instead of explicit checks."
>>
File: 1460119270215.jpg (28KB, 400x400px) Image search: [Google]
1460119270215.jpg
28KB, 400x400px
==30870== 
==30870== HEAP SUMMARY:
==30870== in use at exit: 0 bytes in 0 blocks
==30870== total heap usage: 6 allocs, 6 frees, 1,104 bytes allocated
==30870==
==30870== All heap blocks were freed -- no leaks are possible
==30870==
>>
For C:

If I define an array of characters like char arr[1024];
and then proceed to iterate through it beyond i = 1024, does it bound check and give me a segfault?
>>
>>56975275
The OS _might_, lol.
>>
>>56975260

She didn't go to a UI design interview. She took her UI design, assumed she could program, and threw a fit because she couldn't pass a programming interview.
>>
>>56975266
See, wasn't that hard to use malloc.
>>
>>56975266
>6 allocs, 6 frees
Congratulations, you're not a complete retard.
>>
>>56975275
C usually has no bound checking on array accesses (but some compilers have options to enable it).
Once you've gone past the end of the array, it's undefined behaviour. There is no guarantee for what will happen.
Maybe you will segfault or maybe you'll just read what's there in memory.
>>
>>56975275
no, you just read whatever is on stack beyond that array
if you write data there, then you might important things, which might result in crash
>>
>>56975296
*free
Damn, I'm tired.
>>
>>56975275
UB
>>
>>56975311
>implying I'd write a program that'd accidentally important things
>>
>>56975329
might corrupt important things
I accidentally a word
>>
File: s6je.jpg (147KB, 1024x1293px) Image search: [Google]
s6je.jpg
147KB, 1024x1293px
>>56975319
>>56975311
>>56975304
>>56975285
I just tried it.
Segfaulted ;___;
>>
>>56975345

I just malloc a huge chunk at the beginning of my programs and then put everything inside it. You'll only segfault if you go beyond the container chunk but it usually isn't possible.
>>
>>56975345
FWIW
#include <stdio.h>

int arr[0];

int main() {
printf("%d\n", arr[1]);
}

prints 0 for me
>>
>>56975345
>Segfaulted
On your platform specifically, there are plenty of reasons why your program might have segfaulted due to the invalid access, so don't go assuming that an invalid access will always segfault, it could very well just cause some strange behavior in your program.
Always be aware of your bounds and never go out of them.
>>
>>56975366
>0 size array.
That's not valid.
But even then, it's undefined behaviour. The output is meaningless.
>>
>>56975365
This is not good practice.
You WANT it to segfault on an invalid read.
>>
>>56975371
Yeah I'm aware. Though it's sad that the current environment I'm in restricts this behaviour.
>>
>>56975377
What's meaningful is that "undefined behavior" doesn't translate to "always segfaulting" in this context. Sometimes "undefined behavior" always means one case in practice.
>>
This is gross.

https://www.linux.com/blog/should-math-be-prerequisite-programming

Why do people who can't do math, who suck at computer science, believe they are nonetheless entitled to be hired as programmers?
>>
>>56975383
This is good for performance. Allocation calls cost cycles.
>>
>>56975406
It's not about whether or not they can theoretically, it's about having to do so. Programming doesn't require hard math.
>>
>>56975289
kek
>>
>>56975433
>Programming doesn't require hard math.
Yeah but the article is just using "math" as a weasel word. She wants more programmers who can't program
>>
>>56975406
Wow, that is some retarded shit.
>>
>>56975365
Just use a memory pool
>>
File: cute anime pic 0608.gif (885KB, 459x410px) Image search: [Google]
cute anime pic 0608.gif
885KB, 459x410px
>>56975406
You just need any excuse to feel good about your worthless maths degree, right?

CS graduates are so full of themselves.
>>
>>56975451
I didn't get that impression.
>However, Carol talks about some skills that are important, like logic skills and language. Recursion and loops are also fundamental concepts that can be introduced before math.
It feels like she values the right concepts. I think that if you're good at programming you'll probably be good at math, but a lot of people are just front end devs who don't need to learn calculus. It's a massive waste of time and energy for those people.
>>
>>56975465
That IS a memory pool.
>>
>>56975470
Letting people without CS experience program only leads to retarded shit.
>>
>>56975484
Ya, it just seems questionably managed
>>
>>56975489
Letting people who can't figure out the difference between math and "CS experience" program leads to some retarded shit (eg your post).
>>
>>56975489
In my experience, CS people cannot program.
You must have taken a watered down CS curriculum.
If your CS courses require a computer, they're not a real CS class.
>>
>>56975475
It's not the worst article I've ever read of that sort, I'm just sceptical I guess. I do agree that programming and hard math are false friends to an extent.
>>
>>56975507
>the difference between math and "CS experience"
CS contains math. I don't think anyone can argue against that.
Yes, not all math is relevant to CS or programming, but basic algebra (as the article mentioned) certainly is.
>>
>>56975475
My Uni doesn't even require Calc I for CS. Just College Algebra and a Statistics/Probability course. But most people who don't have a solid foundation of algebra and some calculus are going to do terribly in any CS math (discrete, graph theory, algorithmic analysis, etc.).

If all you care about is educating the equivalent of plumbers or electricians that is the role of trade schools.
>>
>>56975345
gdb
compile with -g
backtrace after crash shows where
>>
File: r4nRg9L.png (26KB, 192x142px) Image search: [Google]
r4nRg9L.png
26KB, 192x142px
>genuinely enjoy writing in c
>feel like a living /g/ meme
>>
>>56975546
>If all you care about is educating the equivalent of plumbers or electricians that is the role of trade schools.
The article's example is about how math is required at a community college. The article doesn't make claims about CS courses.
>>
>>56975212
>No, sane OOP is forgetting about the meme known as encapsulation, having private members is absolutely fucking useless

Encapsulation is good if you're distributing a library, or working with other people. Members and methods can be linked in ways that can make them behave nonsensically if members can be assigned arbitrarily.

For example, let's say you had a rigid body class that contained the members inverseWeight and density. If density changes, then inverseWeight must also change. If one is changed without affecting the other, then your physics calculations are going to behave erratically.

This is mostly irrelevant if you're the only person using your code as you have an intimate understanding of it. But if you're working with other people, it's worth taking the time to encapsulate, because someone will inevitably do something stupid. Likewise, if you're distributing your code, people will be more likely to use it if it's ETUC/HTUI, which encapsulation is a major part of.
>>
>>56975577
>community college
That's not really a tech/trade school. I know a lot of people who went to community college so they can skip out most of the first two years of college at a much lower cost. In some sense they are pre-colleges. But perhaps they should have separate college-bound and work-bound programs.
>>
$("div#pro-stats.buff-pane")
[<div id="pro-stats" class="buff-pane">
<img><span>5.01</span>
<img><span>5</span>
<img><span>5</span></div>]


Does anyone know what javascript code I can use to store each span tag into their own variable?
I tried $("div#pro-stats.buff-pane > span").text(); but that gives me "5.0155"

I've been searching the jQuery api but I don't really know what I'm searching for
>>
>>56975568
>genuinely enjoy writing in c
this is good
>>
>>56975603
>But perhaps they should have separate college-bound and work-bound programs.
This sounds like a good idea, but I'd imagine colleges would want to have introductory courses for everyone and then specialized courses for work vs college bound students. They'd probably still require math for those introductory courses.
>>
>>56975641
(I feel I should also add that this idea was explicitly mentioned in the article too)
>>
>>56975607
$("div#pro-stats.buff-pane span")
This I think should get you an array of the 3spans.
>>
>>56975406
Too retarded; Didn't read
>>
>gayquery
>>
>>56975607
Don't store the results in a variable, just iterate over them normally. If you're expecting specific spans to be bound to each variable then give them specific ids or classes IMO. It's hard to say what the right thing to do is here when I don't know what your problem is.
>>
>>56975406

SJWs and women.
>>
>>56975647
>>56975641
I feel like programming as skilled labor is something that should be sought after. And I think "code bootcamps" should be hunted to extinction. We currently have no way to accredit and rate those as they are unregulated. And usually they produce pretty poor results for what they cost, which is detrimental to both those who want to be educated and potential employers.
>>
File: akari nani.png (254KB, 580x504px) Image search: [Google]
akari nani.png
254KB, 580x504px
How would you implement thread bumping in a board with 150 active threads?

I just had the dumb idea of qsorting thread containers based on the latest non-sage timestamp within that thread and doing this for literally every pageload on the front page.
>>
>>56975733
>I feel like programming as skilled labor is something that should be sought after
What do you mean by "skilled labor?" Why should it be sought after? Do you really think most programming jobs require CS/math/etc knowledge?
>>
>>56975755
I don't see why that wouldn't work.
Do it once, cache the results.
Set a flag every time someone posts.
On every page load, if the flag has been flipped, sort again and reset the flag.

But you should think about maybe using a smarter algorithm than just bump = #1 thread. That could get messy with 150 threads if enough of them are busy. I don't have a better solution at hand though.
>>
I have a shitload of json data representing my sleep for the last year - what do you guys recommend for graphing it and making it look pretty?
>>
>>56975755
>I just had the dumb idea of qsorting thread containers based on the latest non-sage timestamp within that thread and doing this for literally every pageload on the front page.
How about just seeing what order they appear in in the API? IIRC it returns a list for each page, you could just check which one comes first.

Please use the API. Trust me, it's a mistake not to.
>>
>>56975800
(I'm guessing that you like JS if you stored it as JSON) chart.js?
>>
>>56975406
Because women and minorities have the same entitled attitude as spoiled children.
>>
>>56975798
I have a better idea.
Add a latest-bump timestamp column in the active_threads table.
Now i can just sort by timestamps descending.
If a post is submitted as sage, or if it has over N replies, it doesn't update the timestamp.
And this way, I can just archive the one at the bottom when a new thread is made.

>>56975804
I'm not sure what you're saying.
>>
>>56975860
>I'm not sure what you're saying.
He thinks you're making the thread-bumping feature for 4chan, not your own message board.
>>
I'm working my way through this C book and it's just introduced this whole idea of declaring function "prototypes" before main() to me. Is this normal practice?
>>
>>56975755

Quicksorting the threads takes O(n log n) time. Cycling the threads up to the thread that got bumped takes O(n) time, and only needs to be done once per bump, rather than once per page load.
>>
>>56975906
It's okay if you're beginning, though it's more common to declare them in header files.
>>
>>56975909
Anon, do you have some resources to learn O notation? I barely undestand the concept (and always tend to forget it.)
>>
>>56975695
>>56975651

Thank you. It took me 2 hours of searching and I didn't really know what I was looking for at the start.

$("div#pro-stats.buff-pane").children("span").contents()[0];


That's the code I needed to figure out. Now I can go directly to those tags and get the numbers in them to store each one.

I'm trying to read the source from a web page / extension to find these numbers which are going to change each time I reload. Then I'm going to use them to do calculations in a formula. I don't know if I can give these variables specific ids or classes. I understand I'll be able to just call them directly if I could but that will take more time to understand what I'm looking for.
>>
>>56975963
>$("div#pro-stats.buff-pane").children("span")
$("#pro-stats span")

Learn your CSS, dood. ID selectors are already unique, the class and element selectors are useless, and you should use the descendant span selector instead of selecting twice.
>>
What is the best college to go to for video game related programming? My current knowledge goes as far as the flappy bird example.

Or is it better to just learn it yourself with books and websites?

Sorry if this gets asked a lot. Not really sure if this is the right place to ask.
>>
>>56976031
>video game related programming
Don't fucking do it, it's a trap
>>
File: 1412742862372.png (629KB, 674x752px) Image search: [Google]
1412742862372.png
629KB, 674x752px
>>56976031
>video game related programming
>>
File: 1411041262488s.jpg (12KB, 249x250px) Image search: [Google]
1411041262488s.jpg
12KB, 249x250px
>>56975406
>https://www.linux.com/blog/should-math-be-prerequisite-programming
I am so fucking mad right now
>>
What's the best language and why is it LOLCODE?
>>
>>56975406
>ui design
>databases

>programming
>>
>>56975733
>>56975797
if programmers are being devalued by a bunch of normies taking code bootcamps, how can I make myself immune to competition with such people? would knowing maths and C++ and wizard shit like assembly make me a level above this?
>>
>>56976115
>wizard shit like assembly
*basic stuff like assembly
>>
>>56976047
How so?
>>
>>56976115

It'd make you FEEL like you're above it, but then you'd realize that companies actually want you to learn the newest and gayest JS framework.
>>
>>56976120
>unnecessarily limiting yourself to a particular industry
>video games programmers are overworked, underpaid, replaceable and jobs don't last very long
>literally being a /v/ fag
>>
>>56976100
Like it or not, knowing how to use databases is pretty important for most programming jobs these days. Front end design involves a lot of programming too. Programming jobs don't involve a lot of "programming" as college teach you (algorithms etc). Having that knowledge is important, especially if you want to move up, but the majority of jobs don't require it.
>>
>>56976130
and perhaps worst of all
>constantly having to deal with entitled fucking /v/ fags
>>
>>56976135
>>>/g/wdg
>>
>>56976130
>unnecessarily limiting yourself to a particular industry
How is video game programming limiting yourself to an industry? Video games are some of the more demanding things you can do, programmingwise. If you know video game programming, you know programming.
>>
>So, she needed to pass two math courses before she could even enroll in the programming classes, so she needed to spend a year doing math before she could take a programming class. Needless to say, she didn't enroll.
>Needless to say, she didn't enroll.
>Needless to say
What the actual fuck?
>>
>>56976189
Entitlement
>>
File: foo.png (69KB, 628x428px) Image search: [Google]
foo.png
69KB, 628x428px
>>56975811
grabbed it off an api using python - it came in a json format.

I made this is matplotlib, but it's ugly as fuck, does anybody have a way to make a better graph in this style?

midnight is where all those ugly-ass blue dots are on the left there
>>
>>56976169
Yeah but that actually isn't true

>big O
>OS programming
>low level programming (n.b. C is NOT low level)
>doing research
>databases
>WRITING algorithms
>crypto
>servers
>non-procedural, non-OOP
>PL theory, parsers, compilers
>etc


this is what games programming is:
>basic maths (vectors, matrices, trig)
>procedural OOP (feat. Design Patterns (C) (TM))
>implementing algorithms
>parsing and loading asset files
>game design
>AI
>>
>>56976235
You're retarded.
>>
>>56976262
are you >>56976169
>>
>>56971446
C11 is there anything it can't do?
>>
>>56976115
learn the entirety of the x86 instruction set then write your own operating system with a filesystem, audio, commands, etc.
>>
>>56971303
Help, I recently graduated from a theoretical CS school and can't answer this programming interview question: "write a method that converts a floating type number to a rounded string with 2 decimal digits".

Here's my attempt that isn't working right.
    public string ShortenFloatString(float valueToShorten)
{
string xString;
string xString2 = "";

xString = valueToShorten.ToString();

if (xString.IndexOf('.') > -1)
xString2 = xString.Substring(xString.IndexOf('.'));

if (xString2.Length > 3)
xString2 = xString2.Substring(0, 3);

if (xString.IndexOf('.') > -1)
xString = xString.Substring(0, xString.IndexOf('.'));

if(xString2.Length > 2)
{
if(xString2[2] == '9')
{
int num = int.Parse(xString2[1].ToString());
if (num <= 9)
{
num++;
xString2 = "." + num.ToString();
}
else
{
num = 0;
xString2 = "." + num.ToString();

int firstNum = int.Parse(xString);
firstNum++;
xString = firstNum.ToString();
}
}
}
return (xString + xString2);
}


I have to email back the correct response soon.
>>
>>56976235
>this is what games programming is:
>>basic maths (vectors, matrices, trig)
>>procedural OOP (feat. Design Patterns (C) (TM))
>>implementing algorithms
>>parsing and loading asset files
>>game design
>>AI
All this says to me is
>I've never worked on a game before
Games are mostly UI code. AI isn't even a part of actual games, and if you think programming the behavior of NPCs is AI then you don't know what AI is either.
>>
>>56976327
I am actually on a games programming course
>>
>>56976327
>All this says to me is
>>I've never worked on a game before
NPC behaviour is what game devs call AI though.
>>
>>56976323
var sstr = valueToShorten.ToString().Split('.');
string str = sstr[0] + sstr[1].Substring(0, 2);

?
>>
>>56976343
The better be teaching you big O or your course is shit.
>>
>>56976372
Doesn't round at all. Just fix my code.
>>
>>56976393
>Just fix my code.

lmao fuck off
>>
>>56976377
>or your course is shit
I know
>>
Sorry if this should go into the /sqt/, but for some reason today when I launch my script no sound plays. I've rebooted, every other application seems to have access to sound. I use an audio interface that isn't so friendly with linoox but I'm sure that isn't the problem. The code hasn't changed from yesterday.

I literally don't know.
>>
>>56976323
return String.format("%.2f", valueToShorten);
>>
>>56976393
You seriously don't deserve anyones help, you need to fix your fucking attitude right now. Stop devaluating my degree and remove yourself from the gene pool.
>>
>>56976372

I doubt that's what they were looking for, to be honest.
>>
New thread:
>>56976481
>>56976481
>>56976481

Duplicate image edition.
>>
>>56976416

plz respond
>>
>>56976489
I don't want to sound like a dick, but are you speakers/headphones plugged in? Can you play other sounds?
>>
>>56975933

Any entry level computer science class. If you can't get into uni, just read CLRS. It's the textbook that every class without exception reads for algorithms shit, and it should have a good explanation of Big O. You can find it on any decent torrent site because of its ubiquity.

Alternatively, just read Wikipedia.
>>
>>56976610
Thanks, IIRC the first book that I read where O notation was introduced was The Practice of Programming, but AFAIK is not very extense on that topic. Going to check that book.
>>
>>56976323
Just give an example and let me show you how someone that's been learning to code for a month can do something you can't
>>
File: 1.png (65KB, 461x445px) Image search: [Google]
1.png
65KB, 461x445px
>>56976323
I can't tell if this is bait
>>
function otherGuysProblem(num){
num = num.toString().split(".");
if (num[1].length > 3){
num[1] = num[1].slice(0,2) +
(Math.round(Number(num[1].slice(2,4)) / 10));
}
return num.join(".");
}


I did it in Javascript because that's what I know.

>>56976825
I'm sure it is
Thread posts: 321
Thread images: 28


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.