Programming Theory

Programming theory deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features, along with introductory programming concepts like program structure, variable declaration and conditional and looping constructs. Sub-disciplines include the formal semantics of programming languages, type theory, program analysis and transformation, comparative programming language analysis, metaprogramming, domain-specific languages, compiler construction and run-time systems.

Share tech news, updates, or what's on your mind.

Sign up to Post

Suppose I have user input values that I don't know ahead of time and I want to pass these values while creating the product.
Do I pass the values to the Director class or do I pass the values to the Builder class before passing the Builder object to the Director?

Possibility #1:

So, if I pass the values to the Director class, it would look like this:

             IProductBuilder myProduct = new ExpensiveProductBuilder();
            Director director = new Director();
            director.BuildProduct(myProduct, argument1, argument2);

Open in new window


Then in the Director class:

    class Director
    {
        public BuildProduct(IProductBuilder anyProduct, Base arg1, Top arg2)
        {
            anyProduct.BuildBase(arg1);
            anyProduct.BuildTop(arg2);         
        }
    }

Open in new window



Possibility #2

On the other hand, what if I pass the values to the Builder class before passing the Builder object to the Director?
So, if I pass the arguments into the Builder class it looks like this:

            IProductBuilder myProduct = new ExpensiveProductBuilder(argument1, argument2);
            Director director = new Director();
            director.BuildProduct(myProduct);

Open in new window



And then the Builder class would look like this:

    class ExpensiveProductBuilder
    {
        Product baseProduct = new Product();
        Base arg1;
        Top arg2;

        public ExpensiveProduct(Base arg1, Top arg2)
        {
            this.arg1 = arg1;
            this.arg2 = arg2;
        }

        public void BuildBase(arg1) { /* . . . */ }
        public void BuildTop(arg2) { /* . . . */ }
    }

Open in new window



Which of those two possibilities, if either, is the correct way or the usual way of passing arguments in a Builder pattern ?
If neither, then how is it done? Thanks.
0
Hi,

public class TestStringImmutability {

	
	public static class PrintName {
		public static void main(String[] args) {
			String greeting = "Hello my name is ";

			printMyName(greeting, "Doug") ;
			// "Hello my name is Doug"

			printMyName(greeting, "Sam") ;
			// "Hello my name is Sam"
		}

		public static void printMyName(String g, String name) {
			// Does NOT change the original greeting String - which is immutable
			g += name ;
			System.out.println(g);
		}
	}
	/*public static void main(String[] args) {
		// TODO Auto-generated method stub

	}*/

}

Open in new window


output
Hello my name is Doug
Hello my name is Sam


why i was forced to write above cass as static by compiler to compile code. I never remember writing any class as static? what is significance of static for a class? How to execute above code without static keyword. usually static used for class members to make them global right (for method and variables without need to create instance to call them). please advise
0
Hi,

I am working on below challenge
http://codingbat.com/prob/p169260

Psedo code description of approach :
1. loop though given array
2. check where is 1
3. check where is 2
4. if 2place is somewhere further down than by 1 return true
5 else return false
I wrote my code as below
public boolean has12(int[] nums) {
  int onePlace=0;
  int twoPlace=0;
  for(int i=0;i<nums.length;i++){
    if(nums[i]==1){
      onePlace=i;
      
    }
     if(nums[i]==2){
      twoPlace=i;
      
    }
  }
  return (twoPlace>onePlace);
}

Open in new window





I am passing all tests

How to improve my design, approach, code? please advise
0
I'm writing a program that will pre-installed on some raspberry pi devices and each pi will need a unique device id and some other parameters defined in order to connect to a remote service.

I'd like to create a file with some JSON inside to hold these values and the python code would simply peek into the file to get the values for the device it is running on.  Is this a good approach?  Would you use JSON?  Where would you put the file? (in bin with the code, in etc? somewhere else?)
0
Hi Experts,

I have a table named Employeestbl and it entails information of almost everything belonging to the employee, including for example all health documents expiration dates .

In other words any information that an employee can only have one (one to one relationship) is part of the table..

Now I got the request to list all employees that have some documents expiring in given date range.

Was planning to create a Union query of all documents and then filter for the date range, wondering if this is the best way regarding efficiency to deal with this situation (Besides of remodeling the DB of course..which I'm not up to at this point:)?

Attached screenshot to show how the table looks like.
untitled.png
1
I am seeking some design guidance, so I don't wonder down the wrong road or reinvent the wheel.

I'm working on an application (using Visual Studio 2015 - C#) where multiple users will be able to log in to their user account and receive individualized training.

Each user will be presented with a list of lessons choices - lets assume Lesson 1 - Lesson 10. They'll have the ability to choose which lessons they need to take in order to learn how to build a "Widget."

So, User1 checks off lessons (1, 3, 4, 6, 8, 9 and 10). User2 checks off lessons (2, 4, 6 and 8) and User3 chooses to take all the lessons, because he has no prior knowledge of who Widgets are built. -- They then all begin to take their training, but stop at some point prior to completion (they will resume training at a later date).

So, my question is - what is the best way to preserve the choices of:

1). Which lessons they've chosen to take,
2). Their progress.
3). Their scores on any quizzes.

What I want to do is have a mechanism, where, when User2 logs back in she knows she had selected lessons (2, 4, 6 and 8) AND that she had only completed lesson 2 and is halfway through lesson 4, with 6 and 8 remaining.

I assume I can put their choices and progress back into the SQL Lite databases, where their User data (name, ID and Password, etc.) resides, but is there a better configuration approach for such a situation?

Also, if I use the SQL approach (or for that matter any approach), what …
0
Hi,

I am working on below challenge

http://codingbat.com/prob/p139411

I am not clear on challenge desciption and  how to approach. please advise
0
Hi,

I am working on below challenge

http://codingbat.com/prob/p197890

I am not clear on challenge desciption and  how to approach. please advise
0
Hi,

I am working on below challenge

http://codingbat.com/prob/p195714

I am not clear on challenge desciption and  how to approach. please advise
0
Hi,

I am trying below challenge

http://codingbat.com/prob/p141736


Not sure how to approach. please advise
0
Hi Experts,

I have a new client, a software development firm, who asked me to develop a script for their client that will log into their vendor, download a csv, iterate through it, and finally update the client's database. As my client is in software development, they had specific instructions such as:


I assume you normally work on a local server? In this case there is large footprint for this site both in terms of size and some non-standard server dependencies, so for this initial project please just work on the remote site instead of trying to get it all up and running locally. That said the code you'll be writing is fairly self contained so you can certainly work on the main class implementation locally without too much trouble.

My question is with regards to the bolded part. I feel very comfortable with PHP, and know  some about OOP, but given objective why would you need a class and how would you structure it? The client also provided me the following template for the class:

<?php

// INITIALIZATION ///////////////////////////////////////////////////////////////


// CLASSES //////////////////////////////////////////////////////////////////////

/**
 * This class is responsible for connecting to the Vendor portal and returning product
 * pricing data from it. This data will later be inserted into ProductImportData.
 */
class PWIntegration
{
	public function __construct()
	{
		
	}
	
	
	/**
	 */
	public function 

Open in new window

0
HI, I have a question that is focused on development experience and best practices. I thought I'd ask the experts before I jump into quicksand and not realize that I'm sinking until I was shoulder deep.

So... I've been working on a Visual Studio C# Windows Form application that could potentially be used on a large number of computers (any brand any display size). My question is regarding how to format the UI, so that my application is consistent across many, many different display sizes and types.

My application is technical tool. It would be a type of application used by a vertical market and perhaps a niche market at that.

So...here is the problem. We all know that a laptop typically has a smaller display than a desktop and that desktops today sometimes have multiple monitors that are 24", 27" or more - hence a huge variety of displays options.

My question to the forum is -- What is the "best practices" approach to formatting or designing the UI, so that a user on a laptop has the same experience as a user on a 27" display?

Should I make my application footprint smaller and employ Tab-Sets so that the user views the different sections on different Tabs or should it be all in one large layout.

For example, if I make my application Form Window expand to the full size of the display at startup, that will have one look and feel on a 15" laptop and a totally different appearance on a 24" display and even a more different one on a 27" …
0
I can read the file contents and loop thru the records in the file and use that information.
I need to read the contents of a folder that contains image files and loop thru those records and build an array. I'd like
to build an array that contains multiple columns for each item so that I can capture the metadata as well.

I've googled for examples and can't find anything.  I'm new to C#.  I can't find any information on how to do this.

Thanks for any suggestions or sample code.
0
I'm looking for a Bootstrap template that would mimic the look and feel of a Visio Drawing.
Any ideas?

Thanks!
0
I am trying to create images for a website that will allow the user to drag images from one column to a Drawing Board to build their Workstation, etc.  

1) What is the best way to find images for various components such as Monitors, etc?
2) Is there a way to build layers on an image that have a Name that can be used in code for the "parts" that make up a Monitor such as USB Port?

Thanks for any tips!
Crystal
0
I'm looking for some "standard official" definitions of terms such as:

Software Engineering
Computer Programming
Computer Science
Systems Engineer
Systems Design
Systems Analysis
Embedded Systems


I did find:
24765-2010  -  Systems and software engineering -- Vocabulary
http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=5733835&filter=AND%28p_Publication_Number:5733833%29http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=5733835&filter=AND%28p_Publication_Number:5733833%29

But they want $342.
0
I've been trying to wrap my head around how to loosely couple a set of objects.

First of all, I have a set of product objects:

class Acme implements IAvailability {

    /**
     * The price of the product.
     *
     * @var float
     */
    protected $price = 9.99;

    /**
     * The name of the product.
     *
     * @var string
     */
    protected $name = "Acme";

    /**
     * The description of the product.
     *
     * @var string
     */
    protected $description = "Acme";

    /**
     * Determine whether a product is available to an onnet or offnet address.
     *
     * @return boolean
     */
    public function onnet()
    {
        // TODO: Implement onnet() method.
    }

Open in new window


There are multiple products sharing similar properties, just differing in price, name etc -- that's not the problem.

Each of these products will go through a billing cycle, the cycle has three options:

Rolling month
Upfront (one-time only)
Fixed amount of monthly payments

I'm trying to find a way to apply one of these cycle options to a product without hardcoding a return string like:

public function billing()
{
    return 'rolling';
}

Open in new window


Each cycle is an object itself, so I will have a Rolling, Upfront & fixed class to represent the difference in behaviour for each cycle.

How could I achieve loosely coupled design between products & billing cycle?
0
What is the best Design Patterns use for C# developments and  what is the most common and demand Design Patterns for the interviews?
0
We have an ASP.NET application which has a reporting component. When the user runs the report, he selects various filters that we try to parse using the following example:

string lenderIds = string.Join(",", parameters["specificLenders"].AsDomainObject().Cast<Lender>().Select(l => l.Id).ToList());

You can imagine this gets tedious to code this millions of times for all the reports. So we created a helper class, ReportParameterCollectionValuesHelper (code below), to automatically handle retrieval of user input data for us. We simply call it using the following line of code:

ReportParameterCollectionValuesHelper helper = new ReportParameterCollectionValuesHelper(I1Parameters);

Now to access all the user input data, you just call it's properties, such as helper.LenderIds.

The problem is that this class is quickly growing out of control. To add a new type of filter parameter type, we need to modify a lot of code inside this helper class. So I was wondering if anyone could suggest an appropriate design pattern to refactor this class.

Would Abstract Factory be useful here, or Builder pattern perhaps?

public class ReportParameterCollectionValuesHelper
{
	#region Private Fields
	private const string BeginDateFilterName = "BeginDate";
	private const string EndDateFilterName = "EndDate";
	private const string TotalsOnlyFilterName = "Output";
	private const string SpecificAgentsFilterName = "specificAgents";
	private const string SpecificEntityFilterName = 

Open in new window

0
Q1:
Just heard over the local radio that  algorithmic trading is open to retail traders:
heard that the system recommends the entry point/price & the cut loss point
but it's the trader who decides at what point to take profit : is this so?

Q2:
As I'm new totally to this, anyone can point me to beginner's websites with tutorials
& how it works.

Q3:
Anyone has done this & care to share the success/failure details?

Q4:
As it's frequent trading (ie in & out of the positions), how do we minimize
/avoid paying too much commissions to the broker?

Q5:
Can anyone quote a few tools / products that does this?  Heard it's mostly
for index trading though it could be applied to forex & stock trading
0
i am currently try to remove node background white color i try to use TargetCanvas.Brush.Style := bsClear; inside BeforeCellPaint event but the white background of node still visible how do i remove that white back ground color of node ? here what i tried

procedure TForm2.VTs1BeforeCellPaint(Sender: TBaseVirtualTree;   TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;   CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); 
var Data: PUData;
 begin
 Data := VTS1.GetNodeData(Node);
  if not Assigned(Node) then Exit;
 TargetCanvas.Brush.Style := bsClear;
 end;

Open in new window

0
I'm trying to "sell" the time/effort to upgrade some old websites wrote in Classic ASP to C# - hopefully use MVC.
Do you have any articles or tips on some selling points that I could use?  

Thank You!
0
I would like to develop a system to differentiate laser pointers from
the ambient light observed by a team of aircraft pilots,flight engineers
and flight attendants based on the information collected by two arrays of detectors
embedded inside the cavity of a commercial airliner windows including the cockpit.
The first array of detectors measures the HSV color saturation by converting
24 bit RGB color depths.  The second array of detectors measures the spectral bandwidth
after the incoming light wavefront is projected onto a diffraction grating.
 
Saturation is how pure the color is from spectral point of view.
For example, a laser has a very narrow spectrum, which implies high saturation.

If a laser has high saturation, is the converse true?
In other words , If I measure RGB and convert to HSV,
Does high saturation imply that it must originate from a coherent laser source?
the answer to the previous question is not necessarily a laser.
But it's hard to have a saturated color with a wide spectrum,
since the wider it is, the harder it is to have a high response in only one component.

Is it feasible to develop such a system for differentiating laser pointers from
the ambient light? If so, what might be the design parameters be for it?
0
I transferred my project from vb6, and now it is working fine in vb.net
only the menu bar that I created in VB6 is missing. Can anyone advise how I go about re-creating the menu bar in VB.net?
0
What does line with closed triangle BLACK (filled) arrowhead means? Usually arrowhead is either "open" or "closed" but empty not filled in, what is the difference?

Class Diagram
0

Programming Theory

Programming theory deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features, along with introductory programming concepts like program structure, variable declaration and conditional and looping constructs. Sub-disciplines include the formal semantics of programming languages, type theory, program analysis and transformation, comparative programming language analysis, metaprogramming, domain-specific languages, compiler construction and run-time systems.