Please critique my implementation. Join Strings by separator. by alexandream in C_Programming

[–]geocar 0 points1 point  (0 children)

Also, I think the 'static' keyword shouldn't be there.

With static, the compiler knows this block of code cannot exist outside of this compilation unit which has a performance impact (My benchmark of 100,000,000 iterations on an 1.7Ghz i7 takes 26 seconds with your code, versus 23 with the authors).

I'm also a fan of avoiding single-use functions.

Please critique my implementation. Join Strings by separator. by alexandream in C_Programming

[–]geocar 1 point2 points  (0 children)

There's a lot about hygiene in this thread, so I won't comment on choice of NULL or spaces or whatever. Every company I've worked for wants to do that differently, so just program like the locals as far as that goes.

If you make a library function that calls malloc() (or realloc or any other resource allocator) you should also provide a routine in the same library that calls free(). This is because a program might have multiple allocators and this will introduce subtle bugs. This is a mistake many programmers make and it is a very frustrating bug to face because it won't obviously be in the code.

Something else that I think is worth talking about: va_arg isn't very efficient on amd64 which is a very dominant platform at the moment. You might want to consider my macros-based trick:

#define join_strings(s, args...) ({                          \
  char *_args[] = {args};                                      \
  join_strings_(s,_args,sizeof(_args)/sizeof(char*)); \
})
char *join_strings_(char *s, char **invec, size_t n) {
  size_t slen=strlen(s),outlen=slen*(n-1),lens[n],i;char *out=0,*p;
  for(i=0;i<n;++i)outlen+=lens[i]=strlen(invec[i]);
  out=p=malloc(outlen+1);if(!out)abort();
  memcpy(p,*invec,*lens),p+=*lens;
  for(i=1;i<n;++i)memcpy(p,s,slen),p+=slen,memcpy(p,invec[i],lens[i]),p+=lens[i];
  *p=0;
  return out;
}

This is a lot faster (100,000,000 iterations on an 1.7Ghz i7 takes 23 seconds with your implementation but 12 seconds with mine, and it has other benefits: You don't need a terminating NULL (or you can detect it cheaply) which means there's less risk of another programmer making a mistake with your library. This is the single biggest reason I avoid using sentinels.

Pixie - A small, fast, native lisp with "magical" powers by awsometak in programming

[–]geocar 9 points10 points  (0 children)

There is value in differentiating between the CPU in the computer you already have, and the (hypothetical) pixie cpu that someone could build some day.

What's the minimum hardware requirements for you all as developers? by helliax11 in PHP

[–]geocar 0 points1 point  (0 children)

Ah got it.

I was hoping maybe you knew something I didn't: Weight is a very big deal to me, and the MBP is just too heavy.

What's the minimum hardware requirements for you all as developers? by helliax11 in PHP

[–]geocar 0 points1 point  (0 children)

I really prefer my MBA: It's the lightest most-powerful computer I can find, and physical weight is really the most important thing for me, since I travel so much.

When I'm at my desk, I drive multiple displays using thunderbolt chaining.

Some software differences: I don't use phpstorm, and I use docker which really keeps the virtual-machine load down. I run Google Hangouts video and Skype on my phone (which saves me CPU and screen real estate).

Is it possible to make such a program by PirateBoy007 in C_Programming

[–]geocar 2 points3 points  (0 children)

You need to know the length of your array.

If you allow an array to contain pointers to another array, you need to be able to distinguish a pointer to an array from a number.

PHP and WebRTC server-side by hadokee in PHP

[–]geocar 0 points1 point  (0 children)

You can use the same google that I can.

I think if you don't understand what I said, then you'll need to hire a programmer to do this for you.

Good luck.

PHP and WebRTC server-side by hadokee in PHP

[–]geocar 0 points1 point  (0 children)

You can use whatever you want for signalling. When you see how to do it without a server it's a lot clearer; signalling isn't magic, it's just the exchange of the webrtc-formatted peer address.

The weird part is that normally it's done piecemeal - a peer will submit it's knowledge of how it can be reached as that information develops (e.g. by using STUN/TURN), so this is normally done with multiple round-trips, however you can simply wait for all of the addresses and do it in a single transmission.

vs string, or other options by JibblyBibbles in apljk

[–]geocar 1 point2 points  (0 children)

Instead of filtering things out, consider filtering things in:

n:{x where max "0123456789"=\:x}

or (faster):

n:except[;"c"$x where not max "0123456789"=\:"c"$x:til 256]

This is marginally slower than filtering a specific character, but might be more durable.

[scanf] can read string, but what could read sentences ? by rezgod in C_Programming

[–]geocar 0 points1 point  (0 children)

You can, but you shouldn't, for the same reason you shouldn't use gets.

indir() changes the directory just for its block by _perly_bot in perl

[–]geocar 1 point2 points  (0 children)

Yes. The source code is simply:

sub indir ($where, Callable $what) is export {
    mkpath $where;
    temp $*CWD = chdir($where);
    $what()
}

It'd be nice if perl6 had openat so we didn't need the current directory anymore...

Any portability concerns when using VT100 control codes? by fullstep in C_Programming

[–]geocar 0 points1 point  (0 children)

Sometimes a pager is attached and you might still want highlighting. BSD ls uses $CLICOLOR_FORCE for this purpose.

Why does Color.Black != Color.FromArgb(255, 0, 0, 0)? by bonimy in csharp

[–]geocar 2 points3 points  (0 children)

My biggest concern is one has to be very careful to initialize things that depend on color equality and user input (say a color dictionary).

Well, you don't. You can use x.ToArgb() == y.ToArgb().

I suppose if you do a lot of color comparisons, but not a lot of Color instantiation, you could make a Color NormaliseColor(Color x) { return Color.FromArgb(x.ToArgb()); } but I'd be suspicious of the need to do so many Color comparisons.

To become a good C programmer by pgen in C_Programming

[–]geocar 0 points1 point  (0 children)

Then they invariably say, "Well, the compiler should have warned me!"

I agree that the compiler should (as in it would be right for it to, not that I expect it to). I think this is why djb wants BoringC, since it's clearly not a priority for compiler makers.

There's a lot of UB/IB, and some algorithms have very efficient assembly but future me might have preferred I also wrote it in C. Getting efficiency and avoiding UB/IB at the same time is difficult, and even if I'm happy (by checking with objdump) that says nothing about the future: relying on UB/IB is a time bomb waiting to go off!

However since the future version of the C compiler knows when it's being tricky, having it flag which line/module to turn to first on would be very useful.

Is there an easy way to find "tags" in paragraphs of text (summarize it)? by Dialatic in PHP

[–]geocar 4 points5 points  (0 children)

What you're looking for is called natural language processing (NLP). There are lots of NLP libraries.

A good algorithm for finding topics is the Latent Dirichlet Allocation (LDA) with batch Gibbs sampling. Once you know what it's called, a little googling will find you a PHP implementation.

Comparing array elements which are of type double by jony_bobo in C_Programming

[–]geocar 0 points1 point  (0 children)

FLT_EPSILON is defined. You can just use it than an arbitrary nearness.

You can use fdim(d1,d2)<= FLT_EPSILON if you want something without any excess operations.

Safely eval a form in SLIME while running an SDL2 loop? by virtyx in lisp

[–]geocar 2 points3 points  (0 children)

You didn't say what CL implementation you're using. If your main-loop is running in a separate thread, you might try using handler-case to catch all errors running off of the main loop (and save the last one in a global variable someplace).

AMD responds to Linux kernel maintainer's rejection of AMDGPU patch by adnzzzzZ in programming

[–]geocar 2 points3 points  (0 children)

It also means every video driver takes a lot more code than it does on Linux. More code to maintain means more opportunities for bugs, and without some (expensive) care, it makes things slower as well.

AMD thinks their resources are more valuable than the Linux kernel developers', and it's interesting how easily it has been for them to get sympathy from users, who are quick to support them (after all, Microsoft a billion dollar company with near-infinite resources can do it).

AMD responds to Linux kernel maintainer's rejection of AMDGPU patch by adnzzzzZ in programming

[–]geocar 18 points19 points  (0 children)

If the Linux side spent a little more time designing a driver API and keeping it stable

Nobody knows what drivers are going to need which is why even Microsoft changes their driver API with every release, and so with every Windows release drivers get bigger (to support the old API and the new API).

(and don't get me started on DirectX). The Microsoft method produces a lot of code bloat in exchange for that user satisfaction, and it's hard to maintain and hard to improve without also making things slower. Now Microsoft can support a dozen kernel interfaces because they Microsoft and have billions of dollars. Linux however can't, because they aren't and they don't. They can nonetheless compete with Microsoft by simply producing better code which is a whole lot easier if you simply make smaller programs and have less bloat in them, but that means not letting someone dump an extra 100k lines of code that nobody needs and nobody wants (directly).

AMD responds to Linux kernel maintainer's rejection of AMDGPU patch by adnzzzzZ in programming

[–]geocar 1 point2 points  (0 children)

"HAL" is a misnomer: This isn't abstracting the concept of hardware to the Linux kernel, but abstracting the Linux kernel to the hardware.

This allows AMD/ATI's developers to target Windows, and then have a layer that reuses most of that on Linux.

This means that anything that Linux has support for, but does differently, won't be reused by AMD/ATI, so there will be code bloat: two blocks of code that effectively solve the same problem will exist in the kernel. If there's a bug, it may need to be fixed in two places.

It also means that if Linux changes something that this layer expects, the Linux developers need to understand the HAL and what the binary driver is going to do with it. This will introduce stability issues in the best case, and negative brand equity for Linux (oh Linux is unstable, etc).

AMD responds to Linux kernel maintainer's rejection of AMDGPU patch by adnzzzzZ in programming

[–]geocar -12 points-11 points  (0 children)

there's really no good business reason to be doing that twice just for Linux

They are billions of dollars in debt, so I think it's fair to say they wouldn't know a good business reason if it bit them in the ass.

AMD responds to Linux kernel maintainer's rejection of AMDGPU patch by adnzzzzZ in programming

[–]geocar 36 points37 points  (0 children)

This isn't providing an abstract model of hardware to the rest of the system, but an abstract model of the rest of the system to the hardware. In this case, the abstract model isn't all that abstract, it's just exactly what Windows does.