Hot answers tagged

16

def get_range_list(amount, val, end): return [ ('flcon1:DataValue~Osiris_Test_Data_' + str(i + 1) + end, randint(0, val)) for i in range(amount) ] You're only interested in the value of amount, not in the variable it produces itself. Have you tried using xrange instead? xrange is much faster than range. Afar from that, I cut-out the ...


15

Start using New IO The java.io packages have been replaced for a reason. They don't integrate well into what the language tries to become and are at best unwieldy. Instead you should rely on the new IO or nio packages, that work on Paths instead of Strings and have some other advantages. Loading your properties can be simplified to: try { ...


15

Low hanging fruit Most of this will come down to reading PEP8, however I'll state them here anyway. From the top down: If statements don't need brackets, so don't put them around them. Functions at module level should have two new lines between them and other things. Rather than one as you have now. You should use snake_case for functions and variables. ...


13

I'd wrap the <Component>s in a <Components> tag. Maybe you want to add more attributes to spells later. In fact, I'd probably make <ItemComponents> and <SpellComponents>. I'm also thinking you might be better off here and there by using some sort of "quantity". Lets say a spell had 10 components (for some arbitrary game design reason)...


13

They're right. While "</Whatever>" is hard to read itself (YMMV), the constants make it even worse. Magical constants in a code are bad and should usually be extracted as you did. But if there are many of them and each gets used just once, it's counterproductive. The best solution would be something like new XmlBuilder(body) .start("ProductId")....


13

Naming There are .NET Naming Guidelines which state that methods should be named using PascalCase casing. You haven't done this for buildString(). The code The InnerXml property returns a string hence there is no need to call ToString() on the property. Because all methods are public you should do proper parameter validation. At least you should check ...


12

You need to use the two Streams as, well, streams: read a manageable part of the input, transform it, write it to the output and repeat. int bufferSize = 4096; // or whatever char[] characters = new char[bufferSize]; using (var reader = new StreamReader(inFile)) using (var writer = new StreamWriter(inFile + ".NonAsciiChars")) { while (true) { ...


11

WPF readability To keep your xaml looking clean, I reccommend using self closing tags <RowDefinition /> vs <RowDefinition></RowDefinition> Explicitly set properties instead of using the > content area < of a tag. Doing such more explicitly shows what the content is used for. <Label Grid.Row="0" Grid.Column="0" Content="First ...


11

StringWriter and XmlWriter are both IDisposable hence their usage should be wrapped in a using statement The prefixing o of your local variables smells a bit of hungarian notation which generally does not convey a lot of useful information. The encoding has already been mentioned in the comments. In .NET strings are UTF-16 so you use should that instead. ...


11

I wasn't originally going to post this answer as it seems like petty things, but alas, here it is. I mean no offense by any of it, sometimes I tend to type things out to seem that way, but it's all in good spirit. :) Readability issues I was reading through your code and couldn't figure out why it was so hard to read, until I realized you seem to be trying ...


11

Firstly, I'm not familiar with the JavaFX nor PostgreSQL technologies, so my comments will be aimed more at Java-specific code practices. See also the answers by Vogel612 and Antot. Use "try-with-resources" Java makes memory management simpler, because it is a garbage-collected language. However, main memory is not the only resource your program will use....


10

Before anything, I reckon you should have a look at PEP 8 which is the usual Style Guide for Python Code. Among other things, your names for variables and functions does not follow the lowercase_with_words_separated_by_underscores convention. In : def checkAllVersions(self, currentVersion, allHist): historyLength = len(allHist) for i in range(...


10

Josay's answer is excellent. Just wanted to add one more detail: In your code, you use large blocks of comments above your functions to describe what they do. You should consider using docstrings instead. So, for example, your first function would look something like... def loadAllVersions(self, hist): """ Load all version numbers into a list. ...


10

XML based configuration structures often tend to change during the development-cycle of the product. It is good to plan ahead, but you should also expect to run in to something that needs a format change. First though, the structure you have for your XML appears clean, and good. The presentation you have is good and neat. That makes it nice to review. ...


10

Initializing should be done automatically from your constructor. Right now you're exposing it as a public method that may or may not get called: this will guaranteed cause problems when someone forgets to initialize. Considering it doesn't add value in the first place I would just call it automatically in your constructor. Use comments to convey why you're ...


10

public static final String RUBBERDUCK_PATH = "RetailCoder.VBE/UI"; This value shouldn't be compiled into the binary. It should be a configurable setting that's modifiable without needing to recompile. "RetailCoder.VBE" is a relic of the original project, before it was even called "Rubberduck", when the Mug formerly known as @retailcoder was mucking around ...


10

I totally agree with Vogel612's observations. Since there is a lot of code for this review, I'd like to add a couple of items. DatabaseAdapter Class In getConnnection() method, there are three issues, two of them are quite serious: There is a careless call of System.exit(0). I'll just recall a sentence from the good old Hardcore Java about it: If you ...


10

Try this query instead on your data and tell how it performs. Not sure it will return exactly the same as your query but it should be close enough so you can adjust to what you want. select C.CaseName, O.PartNumber, O.NodeName, O.Value as OldValue, N.Value as NewValue from dbo.Cases as C cross apply ( select M.X....


9

Overall, it’s pretty good. I can follow what you’re doing fairly easily, and the docstrings make it easy to see what each function does (even though I’ve not used this module before). Here are some suggestions for how you could make your code more “Pythonic”, and more compact: Take a look at PEP 8, which is the style guide for Python. Two obvious ways in ...


9

@svick's approach is the right one, given these considerations the input file can be as big as 4 GB the data may all be on two lines However I would suggest that regular expressions are the wrong tool for the job, and you will find it faster to use a StreamReader with a specified encoding. There is a method Encoding.GetEncoding that does the ...


9

One should also add that: Both the ReturnNameAsString and the buildString methods could be private as they are not very useful as public APIs. Additionally ReturnNameAsString can also be static because it doesn't use any private instance data. It would be easier to do it with a XDocument because then you can cheat which makes it virtually a one-liner: var ...


8

Consider creating an object which can handle each case: interface NodeHandler { void handle(Node node, Element current, ...); } class ElementHandler implements NodeHandler { public void handle(Node node, Element current, ...) { readElement(node, current); } } You can then populate a map, like this, to look up the appropriate handler ...


8

I don't really like this: case ENTITY_REFERENCE_NODE: if(node.getFirstChild() != null) { element.addEntity(nodeName, node.getFirstChild().getNodeValue()); break; } element.addEntity(nodeName, ""); break; Idiomatically, more than one break in a case is confusing. You should either refactor to an if...else: if(node....


8

Two of the specific requirements on the server side are: server must run until Ctrl-c is pressed. it must process commends in a queue in a separate thread. These two requirements indicate that they want a 'standard' server system, and probably a standard Executor service. I would expect to see code that looks something like: ServerSocket serversocket = ...


8

First, some basics: Vector is a class that is deprecated.... actually, not deprecated, but discouraged.... As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is ...


8

Here's a nice recursive solution, that creates <key>value</key> from 'key'=>'value' entries in your hash. If the value is an array, it instead recurses, using the key name as a wrapper element. require 'nokogiri' def process_array(label,array,xml) array.each do |hash| xml.send(label) do # Create an element named for the ...


8

I don't know what the standards are for Layout Naming on Android, but I can tell you that these names are not very good. textView2 btn_distance_walked textView3 none of these accurately describes what they do. you should probably look for naming schemes on Google. btn_distance_walked doesn't tell us what the button is going to do. What is it going to do ...


8

StackADT: At a first glance, it seems to me that you have over-engineered the stack concept. Do you really need different stack implementations? That would be the only justification for the virtual interface. std::stack would certainly be enough for your needs, and it is most likely more efficient too, as it doesn't utilize virtual dispatch, like yours. ...


8

You have in total three functions over 300 lines, so ~100 lines to a function. This is 5-10x too few functions for this amount of code. A lot of your formatting looks like you've used a C-like language and can't handle writing Python. Stuff like if(x): ... # end if which should just be if x: ... You even have ++level which actually just means ...


8

Comparing strings case insensitively is done by using the proper overload: string.Compare(str1, str2, StringComparison.OrdinalIgnoreCase) By calling .ToLower() for each string to compare (4 times for each iteration), you create 4 new strings each time. If you have a lot of (long) strings, this will create a lot of garbage for no reason. In your case you ...


Only top voted, non community-wiki answers of a minimum length are eligible