Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
seiken
Feb 7, 2005

hah ha ha

Lexical Unit posted:

My co-worker told me today that const-correctness isn't worth the speed hit.

I'm not a professional programmer or anything (nothing of the sort) but I never make functions const because I've always thought accidentally modifying an object when you didn't mean to would be a fairly uncommon thing, and I always forget to make some const that should be and then have to search through files adding const to other functions that were called by const ones. I've always gotten by fine, is this a horrible thing?

I do use const when passing by reference though I guess.

Adbot
ADBOT LOVES YOU

seiken
Feb 7, 2005

hah ha ha
True, but that's surely an unintentional bug and therefore not (quite) so much of a coding horror.

seiken
Feb 7, 2005

hah ha ha

Lumpy posted:


code:
try {
  !!appState.length && (currentState = appState[0]) != null;
} catch(e) {}

Woah, why have I never thought of the !! operator before? Since it doesn't do anything you can pepper it around your code to indicate the important bits!

seiken
Feb 7, 2005

hah ha ha

qntm posted:

I guess !! is equivalent to a boolean cast? Like, if the input was appState.length, which is an integer from 0 upwards, !!appState.length will be FALSE if appState.length was 0 and TRUE if appState.length was greater than 0.

Yeah, of course, I was just thinking about with boolean expressions I guess

seiken
Feb 7, 2005

hah ha ha
I kind of agree in principle but really references are an awesome language feature and IDEs these days should totally be able to pop up a signature with the &s there for you to see as soon as you type the ( :toot:
edit: Compromise! Use const references, and pointers for mutable stuff. Either everybody wins or nobody wins depending on what your priorities are

seiken fucked around with this message at 05:01 on Feb 16, 2012

seiken
Feb 7, 2005

hah ha ha
Yeah that's why I kind of agree in principle.

seiken
Feb 7, 2005

hah ha ha
Haha, you can run the output through it over and over to produce arbitrarily large and slow-executing equivalent code.

seiken
Feb 7, 2005

hah ha ha
I love a lot of the boost libraries, but it can be pretty hit-or-miss. I would never even consider using Spirit over something like YACC.

seiken
Feb 7, 2005

hah ha ha

Suspicious Dish posted:

C code:
(!are_parallel() || // if they're parallel...
umm....

The comment is perfectly correct but yes, this weird idiosyncrasy is probably the one reason it might qualify as a horror (still pretty mild, though).

seiken
Feb 7, 2005

hah ha ha
Never mind whatever bullshit about magic quotes which shouldn't come near an interview, I think doing an interview in PHP at all is a pretty huge horror (especially for a PHP position)!

seiken
Feb 7, 2005

hah ha ha

Look Around You posted:

The fact that SQL queries even are strings in the first place is pretty horrible. Using a binary API like most other things would be exponentially better.

Programs in most languages are just strings but the difference is people don't usually build C source code by concatenating arbitrary user input together.

seiken fucked around with this message at 20:21 on Oct 15, 2012

seiken
Feb 7, 2005

hah ha ha

WHOIS John Galt posted:

If I'm reading this correctly, his definition of a prime number is... a number N for which all numbers N-1...0 are also prime?

Nah, the code is actually technically correct, I guess, just the variables are terribly-named and like 80% of the lines are unnecessary (and it doesn't break early).

seiken
Feb 7, 2005

hah ha ha

This is an interesting thing I didn't know about before, at the same time as being a completely ludicrous defense of the actual code in question. Well done

seiken fucked around with this message at 22:59 on Jan 2, 2013

seiken
Feb 7, 2005

hah ha ha

ivantod posted:

And it's also not necessary to test numbers all the way up to N-1, it's enough to go to sqrt(N) because if there is no divisors by that point there can't be any afterwards. Not to mention many other possible optimisations.
Obviously there are many faster ways to do it but missed optimizations like that probably aren't nearly so much of a horror as the other fundamental ones present (like huge sections of pointless code). You may as well say it's a horror not to implement AKS in baby's first python function.

seiken fucked around with this message at 23:17 on Jan 2, 2013

seiken
Feb 7, 2005

hah ha ha
Seeing as we're talking about Lua embedding in the coding horrors thread, I may as well share this definite horror I just wrote:

C++ code:
// C++ functions we can call from Lua

lua_api(hello) lua_arg(std::string, t)
{
  std::cout << "hello you passed " << t << std::endl;
  // Return nothing
  lua_nil();
}

lua_api(multiply) lua_arg(int, t) lua_arg(int, u)
{
  // Variadic macro + template returns any number of values
  lua_return(t * u);
}
This magic file gets included after a bunch of #defines which mean the lua_ macros expand into namespaces, template function calls and so on, to make these into real C++ functions which pop all the arguments off the Lua stack (checking types) and push the return values on.

Then the lua_ macros get re-#defined into completely different things and the file is included a second time from inside of a function body, expanding into a function which automatically registers all the function names and their addresses onto a passed Lua state (so there's no need to maintain a duplicated list of function names "hello", "multiply" or function pointers anywhere in order to expose them to Lua) :2bong:

Edit: mainly a horror because the error messages are going to be loving nonsensical

seiken fucked around with this message at 00:21 on May 2, 2013

seiken
Feb 7, 2005

hah ha ha

Jabor posted:

I do think it's a worthwhile idea to have a lighter-weight language for level designers and such to use to wire things up. Push-button-to-open-door doesn't seem like the sort of thing you need a programmer for, and having to stop designing to ask someone else to wire it up for you seems like it would definitely slow things down. I think the trick is to deliberately make it crippled enough that no-one is tempted to try and implement any actual game functionality in it.

See Kismet from UDK for an example of this taken to an extreme.

Even if you agree that nobody but programmers should write code (which I for the most part do, actually), having a scripting language for real programmers to write real code in still brings you all the flexibility advantages along the lines of iteration without recompilation, easy hot-swapping & so forth. Whether these advantages outweigh having to maintain the interop stuff depends on your project (choice of host language, especially) I guess but they're worth considering even if you're not explicitly focused on the mod scene shindig

seiken fucked around with this message at 00:34 on May 2, 2013

seiken
Feb 7, 2005

hah ha ha
How the gently caress do you make 20K line commits, I don't even get it. Is he just doing huge find+replaces all over the project or what, I don't know.

seiken
Feb 7, 2005

hah ha ha
I stumbled across this thread on another forum that's from a year and a half ago so it's kind of old, but it's too good not to share.

Your opinion on the functionality of a template dynamic list

Basically, a clueless C++ guy ranting for several pages about how terrible the standard library is (while completely misunderstanding it) and showing off his crazy hand-rolled replacement where pretty much every function is called operator=. Some choice excerpts:

quote:

For example, some time back I had a linked list that took probably about 2000 - 3000 lines of code riddled with memory allocation crashes and various pitfalls.

The present one (iteration 4) takes roughly 800 lines of code (scratched out in one day) - this includes both node and list, doesn't crash (bar user abuse - iteration 3 can't be crashed but is less efficienct), it will explicitly report traceable errors, and compared to previous iterations, already has more advanced functions (it's not finished yet).

C++ code:
File = "Test.txt";
File = 'w';
File = "Write this to file.";
C++ code:
RendererProc Renderer;
ImageQueue Queue;
FileImage ImageLoader;

Queue = ImageLoader = "image1.jpg";
Queue = ImageLoader = "image2.jpg";
Queue = ImageLoader = "image3.jpg";

Renderer = Queue;

quote:

I had the last iteration code up to the point where, barring some optimisation, this would have been valid:

File = HTMLData = "http://iono.jpl.nasa.gov/latest_rti_global.html";

And yes, it does precisely what you think it does.

quote:

I am not sure what there is to maintain? It's straight forward enough to use - assignment operators mostly.

seiken
Feb 7, 2005

hah ha ha

Novo posted:

I hear this all the time, and yet vim purists act like it's everyone else who can't adapt to unfamiliar things.

It's not that IDEs are unfamiliar (they're of course trivial), it's that they're obviously inferior.

I definitely used to use IDEs and now do everything in Vim.

vvv subjectively obviously inferior. And I'm only talking about the text editing

seiken fucked around with this message at 18:25 on Jun 4, 2013

seiken
Feb 7, 2005

hah ha ha

https://github.com/search?q=extension%3Aphp+exec+%24_GET&type=Code&ref=searchresults

seiken
Feb 7, 2005

hah ha ha
LoseThos is now TempleOS and has an incredible video on the front page.

seiken
Feb 7, 2005

hah ha ha
God likes six-forty by four-eighty because it's good for children doing art.

seiken
Feb 7, 2005

hah ha ha
C++ code:
#define pirate private

seiken
Feb 7, 2005

hah ha ha

Thermopyle posted:

Am I the only one who had to look this up?

You're not, it's also my new favourite word. Thanks Scaramouche!

seiken
Feb 7, 2005

hah ha ha

Reality posted:

I inherited a rather voluminous JavaScript code base. There were tons of functions called "set_up_[thing]". I kept spelling setup correctly and I was always wrong.

I have a Python codebase where almost every class has a method like that except it's called either "SetUpX" or "SetupX" completely at random.

seiken
Feb 7, 2005

hah ha ha

Crosscontaminant posted:

If you don't have malware and you don't have bugs, protection just slows things down and makes the code complicated.

To be fair, an operating system used by one person ever is unlikely to be plagued with malware.

seiken
Feb 7, 2005

hah ha ha
This was posted on Stack Overflow under the title How to create an array? It's now deleted. I present it here without comment.

quote:

You are about to be provided with information to start your own Google.

Some people posted comments and said this can not be done because google has 1 million servers and we do not.

The truth is, google has those many servers for trolling purposes (e.g. google +, google finance, youtube the bandwidth consuming no-profit making web site, etc ).

all for trolling purposes.

if you wanted to start your own search engine... you need to know few things.

1 : you need to know how beautiful mysql is.
2: you need to not listen to people that tell you to use a framework with python, and simply use mod-wsgi.
3: you need to cache popular searches when your search engine is running.
3: you need to connect numbers to words. maybe even something like.. numbers to numbers to words.

in other words let's say in the past 24 hours people searched for some phrases over and over again.. you cache those and assign numbers to them, this way you are matching numbers with numbers in mysql. not words with words.

in other words let's say google uses 1/2 their servers for trolling and 1/2 for search engine.

we need technology and ideas so that you can run a search engine on 1 or 2 dedicated servers that cost no more than $100/month each.

once you make money, you can begin buying more and more servers. after you make lots of money.. you probably gonna turn into a troll too like google inc.

because god is brutal. god is void-state it keeps singing you songs when you are sleeping and says "nothing matters, there is simply no meaning"

but of course to start this search engine, you need a jump start. if you notice google constantly links to other web sites with a trackable way when people click on search results.

this means google knows which web sites are becoming popular are popular, etc. they can see what is rising before it rises. it's like being able to see the future.

the computer tells them " you better get in touch with this guy before he becomes rich and becomes un-stopable "

sometimes they send cops onto people. etc.

AMAZON INC however..

will provide you with the top 1 million web sites in the world. updated daily in a cvs file. downloadable at alexa.com

simply click on 'top sites' and then you will see the downloadable file on the right side.

everyday they update it. and it is being given away for free. google would never do this. amazon does this.

this list you can use to ensure you show the top sites first in your search engine .

this makes your search engine look 'credible'

in other words as you start making money, you first display things in a "Generic" way but at the same time not in a "questionable" way by displaying them based on "rank"

of course amazon only gives you URLS of the web sites. you need to grab the title and etc from the web sites.

the truth is, to get started you do not need everything from web sites. a title and some tags is all you need.

simple. basic. functional will get peoples attention.

i always ask questions on SO but most questions get deleted. here's something that did not get deleted..

How do I ensure that re.findall() stops at the right place?

use python, skrew php, php is no good. do not use python frameworks, it's all lies and b.s. use mod-wsgi use memcache to cache the templates and thus no need for a template engine.

always look at russian dedicated servers, and so on. do not put your trust in america. it has all turned into a mafia.

google can file a report, fbi can send cops onto you, and next thing you know they frame you as a criminal, thug, mentally ill, bipolar, peadophile, and so on.

all you can do is bleed to death behind bars.

do not give into the lies of AMERICA. find russian dedicated servers.

i tried signing up with pw-service.com but i couldn't do it due to restrictions with their russian payment systems and so on..

again, amazon's web site alexa.com provides you with downloadable top 1 mil web sites in the form of a cvs file.

use it.

again, do not give into python programmers suggesting frameworks for python. it's all b.s. use mod_wsgi with memcache.

again, american corporations can ruin you with lies and all you can do is bleed to death behind bars

again, a basic search engine needs : url, title, tags, and popular searches can be "cached" and words can be connected to "numbers" within the mysql.

mysql has capabilities to cache things as well.

cache once, cache twice, and you will not need 1 million servers in order to troll.

if you need some xdotool commands to deal with people calling you a troll here it is;

code:
      xdotool key ctrl+c
      xdotool key Tab Tab Tab Return
      xdotool type '@'
      xdotool key ctrl+v
      xdotool type --clearmodifiers ', there can not be such thing as a `troll`
          unless compared to a stationary point, if you are complaining, you are
          not stationary. which means you are the one that is trolling.'
      xdotool key Tab Return
create an application launcher on your gnome-panel, and then select the username in the comments section that called you a 'troll' and click the shortcut on the gnome-panel.

it will copy the selected username to the clipboard and then hit TAB TAB TAB RETURN

which opens the comment typing box. and then it will type @ + username + comma, and then the rest.

seiken fucked around with this message at 20:40 on Aug 22, 2013

seiken
Feb 7, 2005

hah ha ha

Lurchington posted:

dammit javascript and/or V8's implementation of javascript :mad:

code:
> 'str' ++ 'asdasd '
SyntaxError: Unexpected string
> 'str' + + 'asdasd '
"strNaN"
https://github.com/jacobangel/lambic/commit/c0b51c16a04ff080774ecb885a50c32bbf552ffd#commitcomment-4039686

I'm not sure why you'd find either of these surprising.

Edit: I mean it's bad as far as loose typing and implicit coercions are bad wherever they pop up, but the parsing stuff is pretty much sensible (same thing happens in most languages, also with - and --)

seiken fucked around with this message at 20:00 on Sep 9, 2013

seiken
Feb 7, 2005

hah ha ha
I'm still bemused at the awful, terrible syntax of that language, the overblown writing, and preposterous terminology (I burst out laughing at

quote:

A pier is an Urbit virtual machine that hosts one or more Urbit identities, or ships. When you run vere -c, it automatically creates a 128-bit ship, or submarine.
). But the other parts (the virtual machine and OS) have some genuinely interesting ideas. The OS is like super diehard unix plus version control and other tricks built in at a low level, and the VM is this wacky but actually pretty elegant little thing where everything is a list and it's strongly reminiscent of the lambda calculus (with something like JIT for speed).

I wouldn't compare it to TempleOS which is an actually crazy person trying to make a substitute for the whole of Windows.

seiken
Feb 7, 2005

hah ha ha
Multiplying by booleans is perfectly concise and natural, e.g. http://en.m.wikipedia.org/wiki/Kronecker_delta and if you think it's terrible code you need to get out

seiken
Feb 7, 2005

hah ha ha

Opinion Haver posted:

But you don't write (i = j) * 2, you write \delta_{ij} * 2. The analogy would be if you wrote boolToInt(i == j) * 2, which isn't unreasonable.

Also don't take style advice from math unless you use single letter variable names and have a roughly 4:1 comment:LOC ratio.

This kind of failure to be comfortable with the most basic rules of your language is why we end up with poo poo like if (bool_value == true) ....

seiken
Feb 7, 2005

hah ha ha

PleasingFungus posted:

...endless rambling about python...

Please don't play golf with your code.

I don't see what this has to do with a bunch of code examples that were very obviously not Python. That you had to switch to a different language (which, in this context, behaves completely differently) in order to argue makes it clear you prefer a cargo cult approach over considering code on its merits.

Using bools as 0 and 1 in C is "code golf" my loving arse

vv or c++ or any language where you can treat the result of a comparison as 0 or 1

seiken fucked around with this message at 19:12 on Dec 19, 2013

seiken
Feb 7, 2005

hah ha ha

Opinion Haver posted:

What? Pleasing Fungus's examples are in Python:

pre:
>>> (True and True) * 100
100
>>> (True and 2) * 100
200
>>> (True and "a") * 100
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

Yes. Nobody else was talking about python.

seiken
Feb 7, 2005

hah ha ha

Suspicious Dish posted:

The same thing is true in C as well.

(C99, 6.5.13p3) "The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it yields 0."

You are programming by superstition.

seiken
Feb 7, 2005

hah ha ha
"Asking forgiveness instead of permission" is among the most terrible of all terrible nonsense "pythonic" rules. Exceptions are dynamic non-local gotos that obscure control-flow and spread the logic of your program across arbitrarily-distant functions. They should be used for exceptional circumstances and absolutely not as a matter of course. If you're forced to use exceptions for control-flow it's because Python is a bad language

seiken
Feb 7, 2005

hah ha ha

Munkeymon posted:

No


Yes(-ish), but that doesn't necessarily make it a horror. They should probably have a different name in Python so people don't freak out when they're used the way they are because they're used for control flow and that's Very Bad in every other language I know of that supports the concept. It freaked me out at first, but it works fine when not abused as shown above (not calling out SugicalOntologist - the stuff further up), so eh. In my fantasy Python 4M, they're called signals or interrupts - something like that.

There's not really any reason it would be less of a horror in Python. If you don't abuse it and only catch the exception one level up as above of course that's not too bad, but when you start depending on control-flow like that it's inevitable the catches will start moving further and further away from the raises and the program will become harder to reason about locally.


vvv that's ridiculous, naming has nothing to do with it. Control flow exceptions are poo poo no matter what the language is or what they're called

seiken fucked around with this message at 18:52 on Jan 16, 2014

seiken
Feb 7, 2005

hah ha ha

tef posted:

I love hearing this argument because I imagine a programmer going LA LA LA I CAN’T HEAR YOU when they discover that exception handling is a form of control flow.

what? Of course they're a form of control flow. They're a really bad form of control flow that you shouldn't use unless you run out of memory or can't open a file, that's the whole point

seiken
Feb 7, 2005

hah ha ha

Tesseraction posted:

After sleeping on it and coming back I realise I misread the original code, but I'm still not sure how changing a jlt instruction to a cmp then jz isn't considered changed semantics?

The language does not define semantics in terms of instructions.

seiken
Feb 7, 2005

hah ha ha
How haven't I heard about Espruino until now?

Let's run Javascript on a microcontroller. Let's reparse everything every time it's executed. Don't put comments or whitespace in loops, it'll slow things down! Watch out, arrays and objects are linked lists so lookup is O(n)! We're all about saving ram, but bools are going to take 20 bytes unless you put everything in a string!

This might be the worst programming trainwreck I've ever seen. How on Earth did it get Kickstarter'd for £100000?

Adbot
ADBOT LOVES YOU

seiken
Feb 7, 2005

hah ha ha

Cancelbot posted:

code:
IDictionary<long, MyCustomType> _superDictionary;

class MyCustomType
{
    IDictionary<DateTime, InnerType> _inner;

    public this[DateTime index]
    {
        return _inner[index];
    }
}

That's bizarre and I don't know why you'd bother. Now you have to add wrapper methods for each Dictionary method you want to use.

A nested dictionary like Dictionary<K1, Dictionary<K2, V>> is equivalent to Dictionary<K, V> where K is a struct with two elements K1 and K2 though, which is a much more useful way to avoid nested generics if you really dislike them for some reason.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply