ugly-code

What's the ugliest code you were forced to write by outside limitations?

What is the ugliest code that you wrote - not because you didn't know better, but because of limitations of the software, the hardware or the company policy? Because of unusual choices in database layouts and programming languages, I once built a C program that read in a SQL database structure and generated another C program that'd read...

PhysX NxActor Question

Hi. As far as I know, using the PhysX API, the only way to obtain an NxActor is from an instance of NxScene using the createActor method. This is really bugging me. I want to keep my code clean, but I feel like there is no choice but to go around passing this scene from constructor to constructor so that classes can make and have refe...

How to make Ruby's N ends look better?

As I write some scripts, I usually reach a point where my code looks like this : end end end end end end I don't know about you, but this look very ugly to me. Can something be done about this? ...

Reading/writing binary structures: how to simplify this code?

Hi folks, I'm writing a network app, which sends and receives a lot of different kinds of binary packets, and I'm trying to make adding new kinds of packets to my app as easy as possible. For now, I created a Packet class, and I create subclasses of it for each different kind of packet. However, it isn't as clean as it seems; I've ended...

Is there a cleaner way to chain empty list checks in Python?

I have a fairly complex object (deserialized json, so I don't have too much control over it) that I need to check for the existence of and iterate over a fairly deep elements, so right now I have something like this: if a.get("key") and a["key"][0] and a["key"][0][0] : for b in a["key"][0][0] : #Do something which works, b...

How to make this ruby method less ugly (nesting)

I have a helper method that creates navigation links for some controllers. def gen_associations(controllers) content_for :leftnav do sorted_controllers = controllers.sort returning String.new do |content| content << content_tag(:h3, "Associations") << content_tag(:ul, :class => "nav") do sorte...

Endianness conversion and g++ warnings

I've got the following C++ code : template <int isBigEndian, typename val> struct EndiannessConv { inline static val fromLittleEndianToHost( val v ) { union { val outVal __attribute__ ((used)); uint8_t bytes[ sizeof( val ) ] __attribute__ ((used)); } ; outVal = v; ...

Is saving to database just to get an ID a bad hack?

I hope the title is not too confusing. I am trying to make folders with linq-to-sql objects' IDs. Actually I have to create folders before I should save them. I will use them to keep user uploaded files. As you can see I have to create the folder with the FileID before I can save it there. So I just save a record which will be edited or ...

PHP: less ugly syntax for named parameters / arrays?

Here's what I am trying to accomplish: function foo($args) { switch($args['type']) { case 'bar': bar($args['data']); // do something break; } } // or something like that Which is basically a way of using named parameters in PHP. Now, in order to build this $args array, I am forced to write ugly syntax like: $builtArgs = a...

WPF: How to make a base class' dependency property read-only_

I have a class public class NavigableViewport3D : Viewport3D. The class should hide the the Viewport3D.Camera property, so that it becomes read-only. Here's what I have so far: public class NavigableViewport3D : Viewport3D { protected static readonly DependencyPropertyKey CameraPropertyKey = DependencyProperty.RegisterReadOnly( ...

Python: Shorten ugly code?

I have a ridiculous code segment in one of my programs right now: str(len(str(len(var_text)**255))) Is there an easy way to shorten that? 'Cause, frankly, that's ridiculous. A option to convert a number >500 digits to scientific notation would also be helpful (that's what I'm trying to do) Full code: print("Useless code rating:" , ...

Guice generics - how can I make it less ugly?

I have an interface Producer<T> and a concrete FooProducer that implements Producer<Foo>. Binding this in guice looks ugly as sin: bind(new TypeLiteral<Producer<Foo>>() {}).to(FooProducer.class); I have lots of these such bindings. I have tried the following: static <T> TypeLiteral<Producer<T>> producer() { return new TypeLiteral...