|
design patterns are the roman numerals of computation. (with apologies to mr pike)
|
# ? Jan 10, 2012 15:04 |
|
|
# ? Jun 4, 2024 18:15 |
|
I've developed a class that represents an image and it's corresponding metadata. Now I have some data files that were generated by a different class. My goal is to essentially import the data files and generate instances of my new class that are based on the data. What is the best way to handle this? Currently, I'm thinking that I could have a class that represents the datafile and then define methods, one of which shares the name of the constructor of the new class. Then it would manipulate the data as necessary and pass it to the constructor. To me this seems better than modifying the parent class constructor to handle a datafile as an input. I'm having a hard time thinking of any other possibilities. Any suggestions or opinions?
|
# ? Jan 10, 2012 22:43 |
|
Modern Pragmatist posted:I've developed a class that represents an image and it's corresponding metadata. Now I have some data files that were generated by a different class. My goal is to essentially import the data files and generate instances of my new class that are based on the data. What is the best way to handle this? Unless your program needs to access and manipulate the data from the old data files I would just write an import method. Have the import method take in the path to the data file, parse the old image data into a new image class, and returned an array of your image class.
|
# ? Jan 10, 2012 22:53 |
|
tef posted:design patterns are the roman numerals of computation.
|
# ? Jan 10, 2012 23:51 |
|
I could use some advice, guys. I'm writing the first of several C++ Qt GUI applications that connect to a remote device (raw TCP, not web requests), send an XML-wrapped command such as "get diagnostics" or "set monitoring to off", receive a response (diagnostic value, or confirmation that configuration change was successful, etc.), parse the XML (storing the element name and value in a QMap as a key/value string pair), then use the parsed value to update the GUI accordingly. There are 150+ such commands, with more on the horizon. Some of the data can be configured by the user (eg modify existing value, click Submit). Unfortunately, there's no way to tell the data types used in the value. Although the result of any of the 150 commands is one of maybe 10 different types (mostly decimal numbers, but also can be a date, or "ON", "OK", "Normal", etc), with about 5 "metadata" values sometimes accompanying for the main value (eg unit, minimum threshold, and so on) there's no way for me as a client-side programmer to tell. The XML follows a very basic element name/value, so when an element contains "metadata", instead of having that data in attributes or child elements, it gives me a single value like this: %/40.00/36.00/37.00/43.00/44.00. I must then parse it manually, by going over the documentation to find out what each of those values is. Additionally, a value like "1" can mean anything from "Normal" to "Enabled" to "Selected" (I could go on) depending on the element. The old GUI (obsolete) they used has each screen with several hundred lines dedicated to parsing, most of it not simple to follow. I was hoping to have a more flexible way of doing this, so that as little of the GUI code as possible is spent on writing parsing that can't be re-used. I cannot change the XML protocol (I already asked) the server uses. I can only touch the GUI, but obviously I can insert a layer between the GUI and the parser. Does anyone have any advice on what I should do to make this maintainable, and scalable to the multiple GUIs I need to write? What I've been thinking about is have a secondary parser that places the parsed values in a map where the key is the name of the command, and the value is yet another map where the secondary key indicates the metadata. For Qt people I was going for QMap <QString, QMap <QString, QVariant> >. This way, from the GUI I can update each GUI element with one or two lines like so: code:
This wouldn't rock the boat, since my co-workers are already using a basic map in the parser. "Oh now you can use a second key to narrow things down if you want". A better alternative could be to store the parsed data in a class that defines the various types and assorted info. I'm not sure about the best way to design it. Have it be an aggregate of several small classes for each of the 15-odd types, with functions like: code:
MachinTrucChose fucked around with this message at 00:13 on Jan 11, 2012 |
# ? Jan 11, 2012 00:09 |
|
So I have some scripts that interact heavily with an Internet "Appliance" using its SOAP API Initially I had to implement it with very few tests because of time constraints. However now that the script is running along I'm having problems figuring out the best way to implement some tests. What is the best approach to interacting with something that is live like a web service? The options I've come across are 1) to do mocks, which for me wouldn't be that helpful unless they could replicate the functionality and responses from this appliance or 2) just run the script on development appliance and fix whatever problems you run into. For example, one of the functions this script has to do is parse a JIRA ticket and check for specific text that contains the information I need. Do I create a mock that just replicates the response of a JIRA ticket or should I have "test" JIRA tickets on the server and have the tests point to those when it runs? Another example: I have to create profiles on this appliance which involves sending a SOAP call (I'm using ruby so I'm essentially using the soap4r wrapper) which returns nil if it creates the profile, but throws an exception if it fails. Would I essentially do tests that mock the SOAP requests or is it better to switch to the development appliance, run actual code on that server and then parse the results from that? Not sure if that makes any sense, I'm just looking for any ideas about how to handle testing when it involves interacting with a web service. Mock it or some other method?
|
# ? Jan 11, 2012 00:17 |
|
Dolemite posted:I'm not sure whether to ask this here or in the Cavern of COBOL reading thread. I have a two-fold problem being a newer developer without a computer science background. The only development methodology that I've found really useful for improving the quality of the design is test driven development - essentially, write unit tests first, get the tests to pass, then refactor once you get stuff working. I think it's counter-productive to sit down and try to come up with an elaborate, over-arching design - if you write the unit tests first, and force yourself to go entirely TDD, there will at least be enough discipline so that whatever you come up with will be testable, and the likelihood of coming up with an design that isn't viable is greatly reduced - and should the design suck, it's MUCH easier to refactor if you have working unit tests.
|
# ? Jan 11, 2012 09:29 |
|
Orzo posted:What do you mean by this? A design pattern is an abstraction that the language enables but does not support. We chastise those who copy and paste code as beginners, but when experts do it is is a "design pattern". In the early days of computing using a conditional goto in a certain way would be an 'if-pattern', or a 'while pattern'. Pushing ret onto the stack would be a "function pattern". We got past that and now we all take structured programming for granted (well, most of us). Now we use objects to make a "strategy" or a "factory" or a "builder". Meanwhile i'm going to stay over here and use my first class functions and named/optional arguments. Peter Norvig makes a good argument for this http://www.norvig.com/design-patterns/
|
# ? Jan 11, 2012 15:15 |
|
Talking of first class functions, in Haskell it's common to apply a function to each element of an array so much so that it's a standard library function. Given that you can manipulate function pointers in C, is something like that possible? A simple definition in Haskell could be: code:
code:
gonadic io fucked around with this message at 16:11 on Jan 11, 2012 |
# ? Jan 11, 2012 15:43 |
|
AlsoD: I do things like that in Forth, and I think it can be a good way to abstract away loops. The main weakness of function pointers, though, is the fact that they can't easily represent partially applied functions because A C-style function pointer doesn't carry a lexical scope with it. That technique is also a little clumsy syntactically if you don't have a convenient sytax for inline/anonymous function declarations.
|
# ? Jan 11, 2012 15:50 |
|
I feel like a retard for not being able to work out regular expressions. I've got a messy HTML document (converted from an Office document) and I'm trying to find and replace all the HTML tags with LaTeX tags. So I want to turn this: code:
code:
I'm using Notepad++, and I can't for the life of me work out how to use the right combination of wildcards to find every instance and replace it in the right way. Can someone point me to a simple tutorial or help get me started? edit: worked it out: <a href="#_edn[0-999]" name="_ednref[0-999]" title="">\[([0-999])\]</a> It wasn't working because I wasn't putting the escape character thing (\) in front of the square brackets. fuf fucked around with this message at 16:50 on Jan 11, 2012 |
# ? Jan 11, 2012 16:33 |
|
How do I know whether someone sent me an uncompiled Gambas project or a compiled Gambas script? If it's the latter how would I run it? Literally never heard of Gambas until today, and it seems for good reason
|
# ? Jan 11, 2012 16:50 |
|
Thanks all for the advice on programming design. Regarding the one bit of advice to use testing to work out code: Sadly, I haven't really used unit testing all that much. I primarily work in PHP (*waits for laughter to end*) and should probably sit down and try out the testing frameworks I've heard about. I've worked at three places now that don't use any kind of unit testing. But in here and in companies that seem worth working for, I've noticed a lot of unit testing goes on. fuf posted:Regex help I know you worked it out already, but in the future, you ought to try Regex Pal. I've used it to help me work out a Regex pattern. You put in your subject text, then can try out different Regexs. The page will show you matches as you work it all out. Its really helped me get very good with Regexs. Dolemite fucked around with this message at 20:52 on Jan 11, 2012 |
# ? Jan 11, 2012 20:47 |
|
I am having a problem with sed in a BASH script... I am trying to comment out all lines that contain a certain ip address, in this case $host... I tried a bunch of stuff but both of these: sed -i '/$host/s/^/#/g' data2 and sed -i '/'${host}'/s/^/#/g' data2 are only matching a single time in the file even though there are 4 lines that should match. So basically, data2 is only getting 1 commented line instead of 4, even though I have the /g in there. Any ideas why it isn't matching all the lines? EDIT: actually it seems something else is going on here... if I change the order of the lines, no lines get commented! EDIT2: more clues, when I run the same command on the CL with the IP instead of the $host variable, it works perfectly... I have it in an if/then statement, will sed only match once in that case? Eyecannon fucked around with this message at 22:41 on Jan 11, 2012 |
# ? Jan 11, 2012 21:57 |
|
EDIT: Aw crap there's an SQL thread. I am stupid.
ChewyLSB fucked around with this message at 22:45 on Jan 11, 2012 |
# ? Jan 11, 2012 22:42 |
|
fuf posted:I feel like a retard for not being able to work out regular expressions. Careful. [0-999] is a character class, equivalent to [0-9]. Check that this find/replace is still working past #10. You probably want [0-9]+ instead. The + means "one or more of the preceding".
|
# ? Jan 11, 2012 23:31 |
|
Dolemite posted:Thanks all for the advice on programming design. Things I've noticed about unit testing in addition to previous comments: 1. It forces developers to use object oriented programming. If your 'design' isn't object-oriented, you're going to have a bitch of a time writing unit tests. 2. It forces developers to properly mock objects and write scaffolding code - say you're writing a program that displays CR images on a screen, and you use a DLL from another company to do the image processing (sharpening/edge enhancement). And say you need to swap out the old DLL for a new one. If you haven't written unit tests that mock out the component and scaffolding code, then you're in for a hell of a time doing guess and check when people start blaming the new module for issues QA is finding. 3. The unit tests themselves serve as MUCH better documentation than documentation. They're all example code demonstrating how the system works, and should cover every capability - rather than having to page through a reference, you have sample code exercising all the intended code of a module sitting right in front of you - that is huge. 4. Good unit tests make continuous integration worthwhile - if you make your CI tool run the unit tests, and you have good unit tests, you can instantly figure out who broke the build.
|
# ? Jan 11, 2012 23:43 |
|
OK, I fixed my previous problem... turns out I had the wrong brackets around my if statement. Now I need it to check that a line is not already commented before it adds the #, to prevent multiple #'s from being added.
|
# ? Jan 11, 2012 23:48 |
|
hieronymus posted:Things I've noticed about unit testing in addition to previous comments: You've never used a functional programming language, have you?
|
# ? Jan 12, 2012 00:16 |
|
qntm posted:Careful. [0-999] is a character class, equivalent to [0-9]. Check that this find/replace is still working past #10. You probably want [0-9]+ instead. The + means "one or more of the preceding". Thanks! It did indeed stop working past 10. I fixed it by fiddling around but it's nice to know why.
|
# ? Jan 12, 2012 00:25 |
|
hieronymus posted:1. It forces developers to use object oriented programming. If your 'design' isn't object-oriented, you're going to have a bitch of a time writing unit tests. I think what you really mean is that your code is broken up into components instead of a giant spaghetti mess. Which really makes sense... if you can't pick a unit to test independent from the rest of the system, you can't really write unit tests. You certainly can write unit tests for code written in C, which doesn't have any object-oriented features built-in to the language.
|
# ? Jan 12, 2012 01:07 |
|
It amazes me when people think object orientation was the first attempt to add structure to code. There is this little thing called structured programming.
|
# ? Jan 12, 2012 18:22 |
|
At work, I periodically need to turn a file (such as a Word document) into a PDF, but we don't have a PDF creator. However, my Mac at home can do it easily. I'd like to set up a way to send an email with an attachment to a specific email address which Mail is watching, have my computer automatically open the file in Pages, turn it into a PDF, quit Pages, email the PDF back to me and delete the original file and/or mail message. I've got a feeling this is the sort of thing that AppleScript can do. Anyone know how?
|
# ? Jan 12, 2012 18:58 |
|
stray posted:At work, I periodically need to turn a file (such as a Word document) into a PDF, but we don't have a PDF creator. However, my Mac at home can do it easily. You're over-complicating things, there are many available for free. If you're not overly concerned about document security, there is even http://www.freepdfconvert.com/
|
# ? Jan 12, 2012 19:13 |
|
baquerd posted:You're over-complicating things, there are many available for free. If you're not overly concerned about document security, there is even http://www.freepdfconvert.com/ Yeah, this works for me when I'm on Windows: http://sourceforge.net/projects/pdfcreator/
|
# ? Jan 12, 2012 19:26 |
|
Also, Word 2010 (and maybe 2007? Can't remember) can save directly to PDF.
|
# ? Jan 12, 2012 19:31 |
|
Expanding on the other responses, http://www.doc2pdf.net/ is my favorite. You don't even need to provide an email, or anything. You just upload a document and then it just shoots it back to you and you can download it right away.
|
# ? Jan 12, 2012 19:34 |
|
If I'm not mistaken there's a service connected with Amazon's Kindle that does this, too. It's not free though. I second the PDFCreator though, it adds a printer just like Acrobat Pro does so any program can use it.
|
# ? Jan 12, 2012 19:44 |
|
sund posted:Yeah, this works for me when I'm on Windows: http://sourceforge.net/projects/pdfcreator/ I've used this one and it's very nice, it shows up as a regular printer (at least on Windows). Just be careful when you install it because there is a sneaky 'install Yahoo Toolbar' option that is enabled by default.
|
# ? Jan 12, 2012 22:02 |
|
OpenOffice/LibreOffice also has "export to PDF" built in, if you already have that installed.
|
# ? Jan 13, 2012 04:53 |
|
I'm having some trouble with R, when trying to create transactions for mining with arules. My data in the DB looks like this:code:
code:
code:
|
# ? Jan 13, 2012 15:55 |
|
I'm finally joining the 21st century and I'm going to write my first webapp. I'm thinking that I'm going to write a "server" component that you only interact with via JSON and then different mobile apps (Android/iOS/whatever) work via that. I'm also thinking that the web interface will basically be HTML and JS with JSON calls to to the server. Is this naive? Is this the way webapps already work and my super awesome idea is just the way things are done? Am I retard and this won't ever work well?
|
# ? Jan 13, 2012 18:34 |
|
Thermopyle posted:I'm finally joining the 21st century and I'm going to write my first webapp. You need to think in terms of resources and representations. As an example, a post is a resource but you can represent it as HTML, plain text, JSON, etc... This is done through content negotiation. Having a HTML representation of all of your resources is handy as it lets you debug in a browser by following links between things. If you need different representations of things then add them and use the HTTP content negotiation mechanism to get them.
|
# ? Jan 13, 2012 18:39 |
|
Thermopyle posted:I'm finally joining the 21st century and I'm going to write my first webapp. It looks like you're trying to reinvent an RPC mechanism tunnelled over HTTP. You can try: Using a format with hyperlinks in, as to maintain the nice web like properties. Quintessentially you write a 'web 1.0' app that can be 'scraped'. This can be as simple as an XHTML page that links to resources in some other format be it json or xml for example. There are a couple of nice properties that fall from this like being amenable to caching, a uniform interface, and loose-coupling. Using someone else's homebrew rpc mechanism. There are plenty already out there.
|
# ? Jan 13, 2012 19:16 |
|
Thermopyle posted:I'm finally joining the 21st century and I'm going to write my first webapp. Eh, not so far off. I believe the Twitter website nowadays is a bunch of JavaScript that calls their public API, for example.
|
# ? Jan 13, 2012 19:17 |
|
mobby_6kl posted:I'm having some trouble with R, when trying to create transactions for mining with arules. My data in the DB looks like this: You'd be better off asking here.
|
# ? Jan 13, 2012 19:51 |
|
I'm a masochist and am making this school project way larger than it needs to be. For my advanced .NET class I'm developing a shopping cart application for a website. Anyways, foolishly, I just went and pulled down over 400 images of products my website will be 'selling'. I'm curious what would be the easiest way to deal with all of these images? Like, write 400 loving insert statements for the database, then parse through a result set in ASP? Quickly re-name all of the images to be numerically incremental and then just loop through that in ASP? I'd like it so the user can click the image and take them to a page that shows more detailed information, but I think this might start interfering with my other classes' homework.
|
# ? Jan 15, 2012 04:36 |
|
Sab669 posted:I'm a masochist and am making this school project way larger than it needs to be. For my advanced .NET class I'm developing a shopping cart application for a website. code:
|
# ? Jan 15, 2012 05:48 |
|
small python questions: I've got very, very basic coding knowledge and I'm trying to brush up by doing some really simple python exercises, I bought a textbook and I've been working my way through it. The book was written for 2.x python, but I am doing it in 3.x and running into some syntax issues I don't understand. The book has a 3.0 edition, so I have downloaded the example programs from that version, to compare My first question is pretty specific, I have the 3.0 version: code:
Second question: Is there a somewhat easy to understand resource for the differences between python 2 and 3? Are they different enough that I should just uninstall 3 and work with 2 for the sake of learning?
|
# ? Jan 15, 2012 23:39 |
|
|
# ? Jun 4, 2024 18:15 |
|
You should just install Python 2. Most of the working world is using Python 2, and it's not worth the pain to learn Python 2 after learning Python 3. eval evaluates Python expressions. It's a controversial language feature, given that it allows your application to have security holes if you're not careful: code:
code:
|
# ? Jan 16, 2012 00:21 |