Jump to content

dennis-fedco

Members
  • Posts

    77
  • Joined

  • Last visited

Everything posted by dennis-fedco

  1. There are some common methods, yes, like computing model name for a product, with a fuction that goes if ($product == "A") $model = ".."; else if $product == "B") $model = ".."; //etc
  2. I do have common things among products, not neccessarily all of them. There are groups and subgroups of products that need specific computations. So in a sense methods I have in the class are like a library. A specific method, depending on the product may call the same function for product A and B, for example. I have "generic" methods right now that have if ($product == "A") { } else if $product == "B") { } and I have ones that do not use product destinction, and just do a small computations that may be be called for several different products. I don't see where to put factory method or why it is needed .. Are you saying I can use it to hide the fact that I may be instantiating different products?... As in, I have {x, y, z}, give me a Product that I can use generically? There is no globally common functions between all products, but there are groups of them. i.e. {A, B, C} may use computations for X, and Y, but products {C, D, E} may use computation functions for Z and W.
  3. I have class MyProductClass { function computeProductA() { doSometing(); } function computeProductB() { doSometingElse(); $this->computeProductCommon(); } function computeProductC() { $this->computeProductCommon(); } function computeProductCommon() { } } And I was wondering ... does it make sense to move out product-specific functions into their own classes and then have them extend MyProductClass. While I think it makes sense to me from an aesthetic point of view, and that I get to use object oriented principles, I could not answer myself as to "Why" I would do that. So, why? Why would I do that, and should I? Right now in the code, various product specific classes instantiate MyProductClass and just use their specific and generic functions, as needed.
  4. This will be somewhat of a brain dump with somewhat vague questions. To summarize it right now, something about "refactoring software" has been bugging me. The length of the process, the work it takes, and the time, and the "no immediately visible results" that it produces. There have been numerous questions on "do I refactor or rewrite". Depending on circumstances, one choice may work better than another, although historically for working projects (projects people are using continuously), refactoring seemed to do better, since it does not break things as much as rewriting does. And when things break all at once, such as when introducing a rewrite (which most likely has different behavior, UI, feel, workflow, etc. etc.), people tend to get upset. Well, refactoring seems to smooth out the 'upsetness' over a much longer period of time. People change as software changes, and each change is not as abrupt as with a rewrite. There are books written about refactoring software. That process takes time and work, `while not changing the functionality of the software`. Little improvements can be done here and there, but the main point becomes improving the internals of the software without affecting the outside behavior, the user experience. From the business end, *there are no changes!*. We have developers *doing busy work* without showing anything to the business, until perhaps much later. Is that bad? Where I work, I have business people scoff at "what have we been doing" quite regularly, and saying things like "add convertion from one unit system to another? Just put it in!" Which ends up me staring into vastness of legacy code and taking 2-3 weeks to "put it in", what in someone's mind takes a day at the most. But that's cuz maybe I'm slow, but I chose to refactor relevant code first, at least moving View items into respective view containers as a first step. What is the purpose of refactoring software? What, per se does it make better? What expectations can be set? What do I do next time someone says "it is taking too long", other than saying ... cuz I am refactoring!
  5. Let's say there is an application where a user would like to use English and Metric systems to enter values. For example, to handle customer orders where customers give data in this or that system, (but not both). From the user-view, all the user cares about is if they can select English or Metric system, enter their values, click submit, and have their data added to the page in their choice of system, and have their values (and choice of system) stay the same. The back end however is set up to do "compute" operations with English system in mind only. So inside back end, before the compute module, all the values should be converted to English. Some things like precomputed constants, that exist in computations are in English unit of measurements. So I have attached an image of what I am thinking .. * first (top) way is one where the front-end takes care of conversions. Back-end is not aware of another system (which makes it difficult sometimes, when trying to display a page back to the user saying "We know you chose system X"), and being aware of chosen system is something that I think is beneficial. * the second (bottom) way is where front end is merely a passing device to back end, and bac-end takes care of conversions. Back-end is also aware of the two systems My question is -- is there a preferred way to design an application when it comes to considerations above? Have a system-aware back-end, or try to localize system to front end only?
  6. I have the following form (attached to this post as a Thumbnail). I want to make it user-friendly, specifically, bring it up to the modern web standards, namely, I am looking for things that that I think are modern and are user friendly and are great when considered by themselves, but together they may even conflict. And I need some help figuring out what will work best for my situation and what is technically possible. Right now the user enteres fields into the form, into the editable fields on the left. Then user can save the fields by clicking Save, or click Del to delete the row. User can Add a new row at the bottom. The things I think will improve the form are: * implement a double-click feature on the editable fields to make them editable, and save them automatically upon `blur` event * user can use `Tab` key to navigate from one `<input>` field to the next, normally, as before, and edit values inside. * user can save all fields entered so far, and restore them via some mechanism (i.e. either to web page or to clipboard, and restore via direct paste for example, or file upload..) * Maybe I can use DataTables, but I have never used it so I don't know what could be done Can you help suggest form or UI improvements for the current form that I have? I may also have some questions on first steps or first examples of implementing particular ones (possibly making a separate post for those)
  7. Thanks. Well, I read up a bit on why switch statements vs polymorphism... (http://c2.com/cgi/wiki?SwitchStatementsSmell) and it just seems to be a preference of choice. (see the very last paragraph starting with "I think one can summarize most of the above opinions as follows"). I have a LOT of legacy code that currently uses Switch statements. I am rewriting some of it to use Polymorphism, but I paused long enough to read that article and to ask questions, like here. It just seems to me that these days the more "popular" technique is the Object Orientedness, which favors Polymorphism. And that is what people recommend. I don't think I'd agree blindly, and it is probably more of a way of how you like your code, or even how you like to think (in objects or in switches). As otherwise there appears to be no objectively measured improvement of one over the other. In other words, it's like moving the carpet around. There is no way to make it fit perfectly, but you can pull it more towards one side, or more towards the other depending on your preferences, or preferences that of others that you choose or are mandated to subscribe to. I wish there was a more objective reasoning behind it but there is not, other than that summary at the bottom of the linked page about function size and about the way one likes to think about code. So overall, I am kinda glad I looked into it. But in the end, it didn't really help other then to help solidify that one is not necessarily is better than the other, but mostly interchangeable.
  8. Found an issue -- in my IDE I can click on a class name where it is being called, and have it jump to the declaration of the class. If I encode the class name as $class = new $className(); I will lose that ability.
  9. To think of it, I was thinking more in terms of resources of the programmer. Understanding the purpose behind 6 classes takes a bit more cognitive power than seeing one class. Or maybe a different kind of cognitive processing. There is a difference between seeing a class called ProductPdfWriter and thinking "ah, I know what this class does", it writes to Products to PDF, and seeing classes like: BasicProductPdfWriter IProductPdfWriter ProductAPdfWriter ProductBPdfWriter ProductCPdfWriter ProductDPdfWriter and going .. what the heck? how complex of a system are we writing to nothing else but to place bits of text on a PDF template? Not saying "I can't do it" or "someone should not do it", and considering "I can do whatever I want with it", but more so expressing my surprise at such complexity which I think is kind of needless.
  10. yep my "issue" with that is that before there was one class and one file. and now there are 6 files - (1 x interface, 1 x base, 4 x product) I guess the good side though is that it makes software more modular. I am not sure why have the Inteface though, to me it only tells the software/programmer that a certain function must be implemented, that's all, and for that one little thing it wastes so many resources -- takes up entire file on file system.
  11. I have a class that adds a special PDF page to an existing PDF. The page refers to a specific product and there are products A, B, C, D. Products B, C, D are similar and with a bit of if/then/else magic I can basically reuse the same function for all 3, but product A is different enough to have its own function. My class looks like this: class AddPdfPage { function addA(&$pdf, $vars) {} function addB(&$pdf, $vars) {} function addC(&$pdf, $vars) {} function addD(&$pdf, $vars) {} } //The way I call it from within the code right now is like this: AddPdfPage::addC($pdf, $vars); AddPdfPage::addB($pdf, $vars); //the variable below contains the product line -- A, B, C, or D //that's the one I said I could use to merge functions B/C/D into one if I wanted to //I could even include product A if I wanted to even though the code there is different. $vars['productLine']; //The code inside addX() functions is something like: function addX($pdf, $vars) { $pdf->addPage($vars); $pdf->addDescription(".."); //that is different based on each specific product line } Assuming I want to add a page to PDF for a paricular product X, how do I write or structure my code? I am not exactly sure. Do I set it up somehow to use polymorphism? Do I do something else? I assume I don't really want to merge products B/C/D into the same function, even if I could, since they physically represent different product lines, so I might as well keep them as such -- separate. But I may want to use some features of the language to clean up and better up my code. The "how", and what techniques do I use, and what my final code may look like is what my post is about. I am thinking of doing something like: class AddPdfPage() { private $pdf; private $vars; private $productLine; function __construct($pdf, $vars) { $this->pdf = $pdf; $this->vars = $vars; $this->productLine = $vars['productLine']; } public function addPage() { switch($this->productLine) { case 'A': ...break; case 'B': ...break; case 'C': ...break; case 'D': ...break; } } } Use that as a jump start and I guess I could use polymorphism by creating separate classes for each product line and extending some base class, if switch statement is not good.. (http://c2.com/cgi/wiki?SwitchStatementsSmell) but I feel like I will be polluting my file system with too many classes and not sure if that's exactly a benefit. So just thinking about how to do this.
  12. I have a task that seems to be complex. Short Description: currently users of the application I am hired to develop have two steps to do when using the app: 1. Select a Product Line (A, B, C, D) 2. Select input parameters for that product line - all product lines have simlar "Main" input parameters, but also each line has its own special features that can be selected. 3. Selections for that product line are shown - the result is a long table or options for that particular product line. Things like price, discounts, product specifications, etc. What the users want now is this: 1. Select input parameters (not sure how to handle individual product lines special parameters yet) 2. Selections for all product lines are shown The code base is legacy code, with code thrown around everywhere. One idea me and my coworkers have been considering is a complete rewrite, since it will help us with writing tighter code, and do what the customer wants. But that will also take time, and there is no spec. The spec is in the code mess. Another one is I am considering now is a "merge". Somehow merge the product lines, since we have the separate product modules (A, B, C, D), there must be a way to consider maybe extending one to include the others, or somehow get me to the end result -- allow users to see selections for all product lines. Do you have any experience, any suggestions on how to do this? I know this needs details, and details are in my code that you don't see, and most likely won't have the time to read and understand anyway. But I am looking for any ideas or encouragement though that may help. And my question is -- is there any kind of procedure or technique or something to deal with the problem I am facing -- merging several separate yet similar modules into one single merged module. How do I approach this, what are some things that could help, etc. That's what I'm looking for.
  13. I have some data that I need to have visualized using 2D graphs. Looking around I see various tools available, in various technology flavors: JS: Google Charts, Flot, HighCharts PHP: phpCharts, pCharts, JpGraph Question I am trying to decide is -- do i want to use JS, or do I want to use PHP. Can someone please share some insight, provide some ideas, maybe shed some things I didn't think about, to help me consider choosing between these technologies? EDIT (thoughts): It seems and I think that JS technology is a bit more "polished" when it comes to graphing, and perhaps has a larger following, and perhaps is a bit more "dynamic" than similar packages done in PHP. On the PHP side, JpGraph is not being mantained but other packages are still in a reasonable condision I think. Is that enough to go with JS? Another area is that JS is client-side only really, so it may be hard to integrate it with anything server-side. aka, it's hard to "call back home" for data for example, so you have to establish all data upfront, when in PHP while on the server side, you can freely call Database as-you-go.
  14. phew, It is an actual question. I was thinking it was a "sticky" post made by admins, and was expecting to see a long wall of text nagging users about how bad it is to ask about code, and essentially saying "oh you are a newb, tough luck, go away and do your own research before you even ask". Well, I am glad this was not it. Very glad. Yeah, echo command immediately expects to see something quoted, or a variable placed after it. It gets confused if it sees something other than a variable, or a quote mark. HTML or any text for that matter is treated as "text" by PHP, and must be in quotes.
  15. First, I gotta say I am new to JavaScript, but not new to languages like PHP/C++. I am working on a large huge JS file that has a lot of things and I have a feeling that it can be made better. How is where I am at a loss. If it was PHP, I'd split that JS file into probably 20 other smaller JS files, aka "classes", and it may or may not be the right thing to do, but let me focus on one particular aspect for now, and maybe deal with others later. Here is the piece of code that bugs the me most (truncated for clarity): if (selection[index].selected) { result += '<TABLE class="list_grey" style="float: left; margin-left: 20px;">'; result += '<TR>'; result += '<TH colspan="2">Data</TH>'; result += '</TR>'; var flag = "All"; if (selection[index].flag == 'P') flag = "Premium"; result += '<TR>'; result += '<TD>Flag</TD>'; result += '<TD>' + flag + '</TD>'; result += '</TR>'; result += '</TABLE>'; } else { result += '<TABLE class="list_grey" style="float: left; margin-left: 20px;">'; result += '<TR>'; result += '<TH colspan="2">Frame</TH>'; result += '</TR>'; result += '<TR>'; result += '<TD>Frame</TD>'; result += '<TD>' + selection[index].frame + '</TD>'; result += '</TR>'; result += '</TABLE>'; } So what it does is this: 1. it gets "selection" var with eval() from a DIV block of HTML page, where that DIV has a looooong prepared-by-PHP JSON string with all the options prepopulated from various sources accessible to PHP. var selection = eval("(" + document.getElementById("result").innerHTML + ")"); 2. It then dynamically constructs and populates further HTML using logic and data found in "selection" var. 3. This particular JS implements a selection algorithm, where basically user clicking buttons can navigate "selection" var forwards and backwards, and as user does, the dynamic portion of HTML updates per behavior defined in the JS file. My Problem / Question: I have a feeling that putting HTML the way it is done here in JS file is not proper separation of concerns and not good way to code. HTML should be. .. in HTML, when possible, but being new to JS I don't know if there is a better way. Is there a more recommended way to code what I have now ?
  16. I did find one downside to this aside from SRP: I compute dimensions first, then weight. If code computing dimensions happens to hit a snag and throw an exception, it pulls out of the class, BEFORE computing weight. So weight is not being displayed when dimensions are "bad", despite the fact that weight can still be computed and shown in many of the circumstances. Aka code doing the weight computations is dependent on the code doing dimensions. I suppose instead of doing computations of dimensions and weight in constructor, I can just assign parameters in constructor, and move the weight/dimensions into separate functions and call those separately . . .
  17. I am still having a problem with this. . . wouldn't this: $crate->getDimensions(); $crate->getWeight(); cause multiple responsibilities? In this case when I create a crate, I will need to pass initial variables for dimensions, and for weight. Initial (input) variables for dimensions are different than those for weight. They could be separated into different classes, such as $crateDimensions->getDimensions(); $crateWeight->getWeight(); ... but then my main abstract Crate class does have (and perhaps should) provide both dimensions and weights. I am conflicted because I have this one class that goes like this (that's the one that uses different variables for weight/dimensions), where different variable groups are {$id, $sections}, and {$size} class CrateTypeA extends Crate { function __construct($options) { // Declarations $id = $options['id']; $size = $options['size']; $sections= $options['sections']; // Dimensions $this->length = (new TypeAData())->length($size); $this->width = (new TypeAData())->width($size); $this->height = (new TypeAData())->height($size); // Weight $this->weight = (new TypeAWeightData())->getWeight($id, $sections); } }
  18. I ended up doing this: $dimensions = $this->getDimensions($options); $weight = $this->getWeight($options); each method calls its own factory to get object and then calls object's method to get weight/dims.
  19. hah.. I have at least 17 classes that make this thing work ... ...... but yes basically I have .. //So I have CrateDimensionFactory factory. it returns proper object $cratingCalculator = (new CrateDimensionFactory())->getDimensionAwareClass($options); //options contain product specs //from object I get dimensions $cratingCalculator->getCrateDimensions(); // returns dimensions Somewhere else I have a combine() method, where I run various possible combinations of products, where user can look them over and decide which one the like best. In the end I may end up with line items like * product 1 (only) //my method returns dimensions for this one object * product 2 + product 1 //my method returns dimensions for both So the combine() method puts things together and will be a good place to put the code for summing the weights as well. I can thus either create a new class that figures out the weights, or put the weights into the "dimension" classes (since those classes can be easily used and already exist in combine() method). I am leaning towards separate classes now as ... better be safe than sorry and "weights" and "dimensions" are different, and even if I separate them needlessly, I think it won't be too bad.
  20. Suppose I am coding up a crating calculator. A crate is a box with dimensions, weight, built of certain material, and having certain contents. The crating calculator I am writing is one that computes dimensions of the box, once given dimensions of variou contents put into it. Right now I have a factory that figures out which contents object to create, in order to figure out contents dimensions. Something like class CrateDimensionFactory { function getDimensionAwareClass(array $options) { return $dimensionAwareObject; } } //later in some code: $dimensionAwareObject->getDimensions(); Now, I want to also put in the weight of crate which is the sum of contents of crate plus the weight of the crate. Question ... do I stick the weight computations into the same factory? i.e. class CrateFactory { function getDimensionAwareClass(array $options) { return $dimensionAwareObject; } function getWeightAwareClass(array $options) { return $weightAwareObject; } } //later in some code: $dimensionAwareObject= (new CrateFactory())->getDimensionAwareClass($options); $dimensionAwareObject->getDimensions(); $weightAwareObject= (new CrateFactory())->getWeightAwareClass($options); $weightAwareObject->getWeight(); I can even stick the weight into the same returned object, where I create a single object from Factory, and then just call $crateAwareObject= (new CrateFactory())->getCrateAwareClass($options); $crateAwareObject->getDimensions(); $crateAwareObject->getWeight(); There are many ways to do it .. I guess. But the spirit of my question is -- should I, do I put dimensions and weights together or separately, and how exactly do I separate them or how exactly do I put them together, with regards to how SRP is concerned?
  21. ginerjm: not sure if I can see the application of your idea to my project. In my case user selects things like various hydraulic requirements in order to build a pump that can handle the liquid pressure that is going to be pumped through it. So from the original selections that the user makes, the algorithm computes various possible pumps that can be built. That includes combinations of the pumps along with other devices that can be attached to pumps, and the graphs of various efficiency measures and throughput and other metrics of the product combination. User then looks for what they need - it can be efficiency, it can be throughput, it can be something else, depending on what they want maximized. Or sometimes the best option for them is not maximixing one thing, but a compromise on price or other things. So looking at options gives them a better view of the possibilities space. I suppose that in theory users can indeed have a secondary menu (or actually put it on the first) saying "hey I want higher efficiency so give me that", or the like which can help narrow down the choices. It will still not eliminate them down to one. I am not sure however that this will work for me .. this is a custom shop and the culture seems to be "give user all options and let the user decide". In other words, while it can be narrowed down, I will still need to load or pre-load options. There is no way to return one anyway as we want more than one option for sales purposes and such.
  22. in other words, how does one implement something like this .. on a high level. I will ask for details if I need more. so first, I have a form, then I submit the form, generate my options via PHP, but ... how do I display them in an iterable form? How do I pass the data from PHP to JS? Do I load everything up ahead of time and have some huge JS object in the browser to iterate about as user presses left/right arrows? How do I go about that?
  23. I am looking for a high-level (but detailed) conceptual technique on making dynamic selection via a web page, where selection options are stored for later use in a database. Scenario: I have various options for assembling a custom-made product. I can select demands that the product must satisfy via a form, and submit my selection to the server. It then runs an algorithm to match my selections to the possible products that can be built to satisfy the demands. There can be anywhere from 0 (not possible to build product), to 1 to 200 various ways to build possible products that match my selection. I will call original user selection as "original selection" and the 200+ options as "options". Right now there is an existing system in place which is a hideous mess of JSON, JS, HTML, and PHP. Maybe the technologies are the way to solve my problem, but the way it is solved now is hard to maintain. I don't know if there is a better way. Right now, all options are being pre-generated via PHP, and are encoded into JSON, then JSON is read by JS, which drives the dynamic selection of options. Then when an option is saved, entire list of options is saved along with it... Then, when we want to know which original selection was made, we read back all the options from the database and the index of the one we actually need. They are in JSON, we decode that, and then we have what we went. It sounds convoluted to me, and I would like to simplify it a lot, potentially rewriting it. How? Basically I want this end-user scenario: 1. User makes selections via form, submit 2. User is presented with all options. Since there are a lot of options we want user to be able to navigate through them in real time. JS may be of value here, rather than doing new page loads, including AJAX page loads. 3. User saves their selection, and results from page are either displayed back to the user or are saved in DB.
  24. I suppose I could do that. That will mean though I need to deal with (and be aware of) different systems when doing computations. And storing original system in the database along with system identifier as well. Kind of seemed a bit murky to me If I can come up with a simple rule-based schematic it will be okay so let's see: * as-is on input * as-is on output * possibly having separate computation routines for each system, or at the least, keep track of which system it is during computations, in order to maintain proper units. It just looked a bit more hairy to me.
  25. I have an application where things are requested/computed/shown using either Metric or English systems. I am thinking that the best way to handle this is to store units in one system, i.e English (as I am in United States), and to only convert them to Metric for the View, when it is being requested. And if Metric parameters are being inputted through a form, then convert them to English on input. So in a word * store, compute, anything back-end, do it in English system. When anything Metric shows up, then * convert-on-output to Metric * convert-on-input from Metric Does that sound like a good plan? Are there any other equally or better-than plans to deal with systems?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.