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

A couple of weeks ago I wrote about the immutable fluent object builder pattern, and how to increase semantic significance and clean code.
 
This is useful in object-oriented programming languages like java, c#, etc.
 
The resulting object builder could have a clean, fluent API that could look like this:
 
final Car pontiacMontana2007 = Car.builder()
.with(Brand.of("Pontiac"))
.with(Model.of("Montana"))
.with(BuildYear.of(2007))
.with(Seats.of(7))
.build();
 
But in many examples of such a builder pattern written in java, the API becomes slightly different, and simultaneously semantically less significant:
 
final Car pontiacMontana2007 = Car.builder()
.withBrand("Pontiac")
.witModel("Montana")
.withBuildYear(2007)
.withSeats(7)
.build();
 
Wait, what? Did the java developers just throw out the data type system, and reduce both Brand and Model to String, and both BuildYear and Seats to int?
 
Yes, yes they did.
 
But why?
 
Well, that's because of limitations forced upon them by the java language developers: in their infinite wisdom, they made the String and Integer classes final. And that means, that a data type for Brand, which SHOULD have subclassed String, CANNOT subclass String.
 
And that unfortunately has lead to 3 solutions:
 
1. Reimplement String in a non-final, extendable way;
 
2. Envelope a String value in a decorator class;
 
3. Give up and just use String.
 
Why am I making this point?
 
Because I want it understood that many design …
0
Cloud Class® Course: CompTIA Healthcare IT Tech
LVL 12
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

I am wondering if anyone can shed some light on what programming language is showcased in the following video:

https://vimeo.com/36579366

The speaker is Bret Victor.  I've tried contacting him directly, but have never gotten a reply, so I thought, "Longshot, but maybe somebody on EE knows him or recognizes what language he is using."

Is this an actual language, or something homegrown / custom - just for the purposes of the demo.  The 2-way-tool "reactive document" nature of the presentation is astounding (to me).

Of particular interest is around time index 9:10 where he appears to interact with the generated image and change the underlying code.  At various other points in the video he changes the code and the picture changes instantly without a recompile (React-esque environment) but the visual tools he uses are unfamiliar to me.  It is not any sort of IDE or language I have seen.

Some of the interactivity looks a lot like Tangle.js:

http://worrydream.com/Tangle/

which seems to be a JavaScript library by the same guy, but I am not sure this library, while very cool, explains everything he is doing in the demo either.

Thank you!

Tom
0
Hi All,

I need your assistance starting a table/relationships similar to an Entity Relationship Diagram (ERD) for storing business objects. Please note this is not for SAP Business Objects.

The definition of a business object is “an entity that describes a person, place or thing that is essential to a business system, which the subject system needs to be keep track of”.

I am not really sure which tables / relationships are needed for business objects. I would appreciate your guidance or examples.

Thank you.
0
I am currently studying software development at a university part-time. I also have to learn UML which I am having difficulties with because I cannot see any vocational relevance.
Where I work, we work agile and I was told that we do not have time to draw diagrams for hours and then make changes to it whenever the code changes.

Does anyone still use UML or is it only used in academia; that is: in research, study etc..

I assume that UML was used when working in the "waterfall model"?
0
Does anyone know of good software design application? Something I could use to visualize the logic of my php scripts before coding?
0
How much effort do you Experts think should go into defensively 'protecting' a text input field (which will be used to obtain key search terms for a text search) from (possibly) irrelevant input from the operator, such as too many space characters, punctuation and other tokens which might not be helpful to an effective search strategy ? I'm relatively ok with implementing methods that are considered helpful, so this is not a request for coding assistance, but rather about approach and real-life search term management and oversight. (I suppose another way of putting the same point it that I wish to avoid second-guessing the inputter whose attempts may well be valid, but look odd in plain discrete standalone terms. Thanks for any suggestions along these lines.
0
Explain Big O notation, Binary Search and Logarithms, C#

I am curious to learn more about Big O, Binary Search and huge data sets.

What sorting and searching methods maximize performance for millions of records?

Is Binary Search still used here?

Thanks

https://codingticks.wordpress.com/2013/07/21/a-beginners-guide-to-big-o-notation/
0
Hi,
I have a simple grammar of a subset of C I'm trying to program using Yacc. In one part of my grammar I have the following rules:
 
DeclarationsAndStatements: Statement DeclaratonsAndStatements
                                                             | Declaration DeclaratonsAndStatements
                                                             | Statement
                                                             | Declaration
                                                              ;

           Statement: error SEMI
                              ;

           Declaration: error SEMI
                              ;

Open in new window


Because I have Statement and Declaration both producing error SEMI I keep getting a shift/reduce conflict, I tried multiple solutions but I keep getting the same conflict. How can I solve this conflict?
0
What happens if a thread acquires a lock (SemaphoreSlim), and then that thread gets terminated before it releases the lock?

e.g.
private SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1);
public async Task DoStuff()
{
    using (semaphoreSlim.WaitAsync(1000))
    {
    	...//Do something
    }
}

Open in new window

What happens if the thread gets terminated while it's in "Do Something"?
0
Need to implement Spring Security for a project.

Option1:

  Structure: User table, Permission table, Module table and PermissionGroup table
  User will have only one permission group.
  Permission table will have read/write/update etc.,
  Module will be product/sales/order
  Permission group table will be product - read/write, sales - read/write/update

Option2:

 Structure: User table, Roles table, Permission table,
 User can have 1 role
 Permission table will have as product_read, product_write, sales_read, sales_write

Comments on Option2:

 We can able to use Spring hasRole() kind of configuration for each method and can associate a role to it.
 Drawback: We cannot have dynamic roles as we can able to do it option1

Comments on Option1:

We can have dynamic groups however we cannot use spring hasRole(). Instead we need to get the manual decisions based on the http request - PUT/GET/POST and check for the permissions configured and decide whether to allow the URL or not in the interceptor.

Drawback:

This may not be a standard practice
What would be the best approach out of this two as well as preferable one?

Thanks.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012
LVL 12
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Hi,
I'm new to C# Language.What is the best Design Patterns i need to follow.
I can understand it's depend on the project,According to yours experience what is the most recommended Design Patter?
0
We have a program that was originally a WinForms program. We converted it to WPF and MVVM. Problem is the VIewModel for the window is still 3000 lines. It's difficult to maintain because I'm always jumping around the file trying to find related parts.

I'm wondering if there's a better way to consolidate this, perhaps different parts could be split into different files.

The window has a toolbar, with several buttons on it, and a couple TextBoxes. There's buttons like Play, Pause, Stop, Open File, Save File, typical stuff. A couple textboxes users can enter times in.

The ViewModel has a Play command, a Pause command, a Stop command, an Open File command, a Save File command. There's a property for TextBox1, and a property for TextBox2. The properties send notifications when they are changed. Standard stuff.

It all just becomes a lot when it's all placed together in the same ViewModel file. Even worse, our coding standard dictates that all fields should go in one place, while all Properties go in another place, so whenever I look at a property, the corresponding field is somewhere else if I want to look at it.

If I'm trying to trace the Play button, for example, the ViewModel constructor sets up the PlayCommand. The PlayCommand variable however is defined elsewhere. The constructor just sets it. Then the Play() method it calls is elsewhere in the file, and the CanPlay method is elsewhere. And mixed in with this all is the code …
0
import org.json.simple.JSONObject;

class JsonEncodeDemo {

   public static void main(String[] args){
      JSONObject obj = new JSONObject();

      obj.put("name", "foo");
      obj.put("num", new Integer(100));
      obj.put("balance", new Double(1000.21));
      obj.put("is_vip", new Boolean(true));

      System.out.print(obj);
   }
}
On compiling and executing the above program the following result will be generated −

{"balance": 1000.21, "num":100, "is_vip":true, "name":"foo"}

Open in new window


what above example doing
is it encoding jsonobject to java object?
i see output also seems like json to me?
Following is another example that shows a JSON object streaming using Java JSONObject −

import org.json.simple.JSONObject;

class JsonEncodeDemo {

   public static void main(String[] args){
	
      JSONObject obj = new JSONObject();

      obj.put("name","foo");
      obj.put("num",new Integer(100));
      obj.put("balance",new Double(1000.21));
      obj.put("is_vip",new Boolean(true));

      StringWriter out = new StringWriter();
      obj.writeJSONString(out);
      
      String jsonText = out.toString();
      System.out.print(jsonText);
   }
}
On compiling and executing the above program, the following result is generated −

{"balance": 1000.21, "num":100, "is_vip":true, "name":"foo"}

Open in new window


how above one is differen from first one?
0
Consider algos/softwares that take keywords in one document and match them (possibly a kind of set intersection) with keywords in N other documents, possibly producing a match ranking.

a. Is there a specific name for this?
b. Are there implementations in Java and PHP?

Example use cases would be
  • patients submitting a list of symptoms and then software looking for matches against known conditions
  • applicants submitting skillsets and looking for potential job matches
  • dating websites
0
See this code:
$piece1 = $test;
$piece2 = "";
$piece3 = "";
$ln = strlen($test);
if ($ln > 84) {

	$arrayWords = explode(' ', $test);

// Max size of each line
	$maxLineLength = 84;

// Auxiliar counters, foreach will use them
	$currentLength = 0;
	$index = 0;

	foreach ($arrayWords as $word) {
    // +1 because the word will receive back the space in the end that it loses in explode()
		$wordLength = strlen($word) + 1;

		if (($currentLength + $wordLength) <= $maxLineLength) {
			$arrayOutput[$index] .= $word . ' ';

			$currentLength += $wordLength;
		} else {
			$index += 1;

			$currentLength = $wordLength;

			$arrayOutput[$index] = $word . ' ';
		}
	}
	$piece1 = $arrayOutput[0];
	$piece2 = $arrayOutput[1];
	$piece3 = $arrayOutput[2];
}	

Open in new window


This works perfectly, except I need a variation where I can limit the FIRST line ($arrayOutput[0]) to 84 & the subsequent lines to 94. See attached image for visual of this need. The text is printed using a pdf generator on an existing form image (with the word Remarks & the lines.)

How can I do this?

Thank you
Capture.JPG
0
hi,
I was writing below example
https://www.youtube.com/watch?v=ShO_Z64sGwI&list=PLZM-6wiKGRfGmXzuR8uX3UsE8g91K6Vp1&index=5

package com.gp.mockito;

import org.junit.Before;
import org.junit.Test;
import junit.framework.Assert;
import static org.mockito.Mockito.*;

public class CalculatorServiceTest {

	CalculatorService calService;
	
	@Before
	public void setup(){
		ICalculator cal_mock = mock(ICalculator.class);
		when(cal_mock.add(2, 4)).thenReturn(6);
		calService=new CalculatorService();
		//calService.setCal(cal_mock);
		
		
	}
	@Test
	public void testAddNumbers(){
		Assert.assertEquals(6, calService.addTwoNumbers(2,4));
	}
}

Open in new window

package com.gp.mockito;

public class CalculatorService {
ICalculator cal;
public ICalculator getCal() {
	return cal;
}
public void setCal(ICalculator cal) {
	this.cal = cal;
}
public int addTwoNumbers(int x, int y){
	return cal.add(x, y);
}
}

Open in new window

package com.gp.mockito;

public interface ICalculator {
public int add(int x,int y);
}

Open in new window

why we need setter for calservice implementation class.

why are they setting interface mock object to the calservice object

observerd one example here
https://www.youtube.com/watch?v=DyuWgBHfxNQ

i do not see any setter here though?
1
hi how to see post man response. i installed post man now instead of advance res client
postMan401.png
postMan200.png
0
Bloom Filter
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data definitely won't be found. Read on to find out more...
6
By mistake i removed the jre default from eclipse java project instead of updating jre with jdk as beow

Here is the complete sequence in Eclipse Luna:
Right click your project > properties.
Select “Java Build Path” on left, then “JRE System Library”, click Edit…
Select "Workspace Default JRE"
Click "Installed JREs"
If you see JRE you want in the list select it (selecting a JDK is OK too)

how to add jdk 1.8
please advise
0
Cloud Class® Course: Microsoft Azure 2017
LVL 12
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

hi,

i am importing existing project into eclipse as non maven project. Everytime i import new project i see bunch of errors. when i go to error and say fix project set up and give jdk 1.8 then issues resolves. why i have to do this everytime to every new project. can i teach eclipse some how to rememebr so that i do not have to give this again and agian. please advise
errorJDK.png
errorJDK2.png
0
hi,

If i do Control+Alt+H on eclipse java class method say methodA() it does show call hierarchy  of who is(lets say methodB()) calling that method (methodA())

If i do control Alt H on methodB() it shows methodC() which is calling methodC()

my question is how to find by selecting methodC() that methodB() is its parent method and methodA() its grand parent method.

i mean to debug upward as well not just downward using call hierarchy.
is there is a way i can do both ways?

please advise
0
Hello, I have the following code while practising for loop but what I don't understand is, why we have a loop inside a loop?? what's the deal here?

<?php

// Create a script to construct the following pattern, using a nested for loop

//* 
//* * 
//* * * 
//* * * * 
//* * * * * 
//* * * * * 
//* * * * 
//* * * 
//* * 
//* 

$n=5;
for($i=1; $i<=$n; $i++)
{
for($j=1; $j<=$i; $j++)
{
echo " * ";
}
echo "<br>";
}
for($i=$n; $i>=1; $i--)
{
for($j=1; $j<=$i; $j++)
{
echo " * ";
}
echo "<br>";
}

?>

Open in new window

0
Hello,

I am looking to create a web-based application that, at a later date, may have a supporting windows program and mobile app (but not for phase 1).

I was considering the language to write the code in and which one would be best and was looking for your advice. These were the high-level requirements.

Will utilize a back-end database.
Will need to create PDFs based on templates and information held in the database (i.e. like an order receipt).
Will need to create PowerPoint, Word and Excel documents based on templates and information held in the database (i.e. create a copy of the order in PowerPoint format).
Allow the user to view information in tables that can be edited directly in the table with a double click or similar.
Ability for the system to generate and send emails
The ability for the system to generate an email in Outlook and save in the user's draft folder.

It would be great to get your thoughts on this given the high-level requirements.
0
I love the notion that my REST web service could deliver a complete UI to the client, which that the client could then display complete functionality inside a window, on their own site. What's kind of client/server relationship is this?

Is this what Code-On-Demand does?

Does it return HTML/JavaScript/CSS?

What kind of control is needed on the client to receive this? An iframe?

What kind of problems might there be with this kind of interaction?
0
Hi,

I ran below example on tomcat 9

https://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/


how to run tomcat 7 as well.

can i keep same ports for tomcat 7 and tomcat 9.

can i start both servers from eclipse same time?


how to keep port nubet more common ones?
please advise
tomcat_11.png
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.